我有一個包含很多元組的列表,以及存儲在streaming_cfg
如何轉儲列表中的元組到一個文本文件在Python
,並試圖轉儲到一個文本文件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')]
您需要_call_的'.close()'方法用括號:' debug_file.close()'。 – senshin