0

テキストドキュメントをインポートするためのコードの下で使用されています。

class text_based_attendance(osv.osv):

    def text_files_upload(self, cr, uid, ids, context=None):
        attendance_v={}
        attendance_obj = self.pool.get('text.based.attendance')
        print('Text Files going to upload')
        with open("/home/priyan/Desktop/Store/HR_Module/attendance/savefile.txt") as f:
            c = csv.reader(f, delimiter=':', skipinitialspace=True)
            for line in c:
                name=line[0]

これが私のテキストドキュメントテキストです(指紋マシン出力テキストファイル)

09D043543011301292:0834*0073*:3:5:G

09D043543011301292:1744*0073*:3:5:G

ここに私のエラーが表示されます

2013-08-16 11:16:00,792 5291 ERROR bell_hr_beta openerp.osv.osv: Uncaught exception
Traceback (most recent call last):
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 131, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 197, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 185, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/addons/hr_attendance/hr_attendance.py", line 227, in text_files_upload
    for line in c:
Error: new-line character seen in unquoted field - do you need to open the file in universal-newline mode?

編集 以下のようにメソッドを変更してからファイルを読み取り、2行目の読み取り時にエラーが発生します

with open("/home/priyan/Desktop/Store/HR_Module/attendance/savefile.txt",'rU') as f:

新しいエラー

2013-08-16 11:22:05,972 5382 ERROR bell_hr_beta openerp.osv.osv: Uncaught exception
Traceback (most recent call last):
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 131, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 197, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/osv/osv.py", line 185, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/priyan/hr_openerp/openerp-7.0/openerp/addons/hr_attendance/hr_attendance.py", line 228, in text_files_upload
    name=line[0]
IndexError: list index out of range
4

1 に答える 1