我有一个包含许多元组的列表,并存储在 streaming_cfg
并尝试转储到文本文件 DEBUG_STREAMING_CFG_FILE
但是,它是一个空文件,不包含任何内容。为什么 ?
debug_file = open(DEBUG_STREAMING_CFG_FILE,'w')
for lst in streaming_cfg:
print(lst)
debug_file.write(' '.join(str(s) for s in lst) + '\n')
debug_file.close
streaming_cfg
[('0', '0', 'h264', '1/4', '1280x1024', '10', 'vbr', '27', '8m'),
('0', '0', 'h264', '1/4', '1280x1024', '10', 'cbr', '6m', 'framerate'),
('0', '0', 'h264', '1/4', '1280x1024', '10', 'cbr', '6m', 'imagequality'),
('0', '0', 'h264', '1/4', '1280x1024', '10', 'cbr', '8m', 'framerate'),
('0', '0', 'h264', '1/4', '1280x1024', '10', 'cbr', '8m', 'imagequality'),
('0', '0', 'h264', '1/4', '2560x1920', '8', 'vbr', '27', '8m'),
('0', '0', 'h264', '1/4', '2560x1920', '8', 'cbr', '6m', 'framerate'),
('0', '0', 'h264', '1/4', '2560x1920', '8', 'cbr', '6m', 'imagequality'),
('0', '0', 'h264', '1/4', '2560x1920', '8', 'cbr', '8m', 'framerate'),
('0', '0', 'h264', '1/4', '2560x1920', '8', 'cbr', '8m', 'imagequality'),
('0', '0', 'mjpeg', '1/2', '1280x1024', '10', 'vbr', '25', '4m'),
('0', '0', 'mjpeg', '1/2', '1280x1024', '10', 'cbr', '6m', 'imagequality'),
('0', '0', 'mpeg4', '1/2', '1280x1024', '10', 'vbr', '28', '6m'),
('0', '0', 'mpeg4', '1/2', '1280x1024', '10', 'cbr', '3m', 'imagequality')]
您实际上并没有在调用close
,而只有一个表达式,该表达式的值为可调用对象。
将最后一行替换为
debug_file.close()
顺便说一句,可以通过使用上下文管理器在现代python中防止此类错误:
with open(DEBUG_STREAMING_CFG_FILE,'w') as debug_file:
for lst in streaming_cfg:
print(lst)
debug_file.write(' '.join(str(s) for s in lst) + '\n')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句