我試圖從一個文件的讀取和使用寫入到另一個文件:讀取和寫入文件,正確縮進和語法高亮
with open('example2') as inpf, open('outputrt','w') as outf:
for l in inpf:
outf.write(l)
但我在1號線即
得到一個語法錯誤"with open('example2') as inpf, open('outputrt','w') as outf:" pointing at "inpf,"
我的python版本是2.6。語法中是否有錯誤?
看看http://stackoverflow.com/questions/3791903/which-python-version-need-from-future-import-with-statement(短版:從__future__進口with_sta加上' tement'在腳本的頂部)。 –
如果這真的是你的代碼,你最好用'shutil.copyfile'。 – sberry
此代碼適用於我.. Python 2.7.2 – Ansari