2
我想學習python,並想寫一些文本到一個文件。我遇到了兩種文件對象。Python-將文本寫入文件?
FOUT =打開( 「的abc.txt」,一)
張開( 「的abc.txt」,a)根據FOUT:
以下代碼:
f= open("abc.txt", 'a')
f.write("Step 1\n")
print "Step 1"
with open("abc.txt", 'a') as fout:
fout.write("Step 2\n")
都給輸出:
Step 2
Step 1
以下代碼:
f= open("abc1.txt", 'a')
f.write("Step 1\n")
f= open("abc1.txt", 'a')
f.write("Step 2\n")
都給輸出:
Step 1
Step 2
爲什麼會出現在輸出區別?
謝謝。但爲什麼在輸出的差異呢? –
我現在還在回答這個問題,我正在分步實施:) – Jezzamon
哦!非常感謝!我無法涉及到文件的寫入與文件關閉的關係。你把它清理乾淨了!謝謝! –