【发布时间】:2020-03-09 00:48:26
【问题描述】:
我正在使用 fileinput 库的 Linux 环境中运行以下 python 代码。
filelist = glob.glob(os.path.join(LOCAL_DESTINATION, "*.*"))
for file in filelist:
if comment_type.lower() == 'header':
f = fileinput.input(file, inplace=1)
print(f)
print(f.__dict__)
for xline in f:
print(4567)
if f.isfirstline():
sys.stdout.write(comments + '\n' + xline)
else:
sys.stdout.write(xline)
The stderr I see even though the file is present in the LOCAL_DESTINATION folder:
'NoneType' object is not iterable
Exception ignored in: <bound method FileInput.__del__ of <fileinput.FileInput object at 0x7fb6164ed240>>
Traceback (most recent call last):
File "/usr/lib/python3.5/fileinput.py", line 229, in __del__
File "/usr/lib/python3.5/fileinput.py", line 233, in close
File "/usr/lib/python3.5/fileinput.py", line 290, in nextfile
TypeError: 'NoneType' object is not callable``
Can someone tell what could be the problem.
附: f.dict 打印出以下内容: {'_file':无,'_backup':'','_openhook':无,'_filename':无,'_savestdout':无,'_mode':'r','_inplace':1,'_startlineno': 0,'_files':('4f5b11ef-601f-4607-a4d0-45173d2bbc53 / q3_2019_placementguid_555168561629745350_f99a8d275e4_11_f99a8d275e4_11_13_2019.txt',),'_isstdin':false,'_filelineno':0,'_backupfilename':none,'_output':none}` ``
【问题讨论】:
-
提供完整的错误信息
-
@AkshayNevrekar 会回复你
标签: python python-3.5