f = open("demofile3.txt", "w")
f.writelines(["\nSee you soon!", "\nOver and out."])
f.close()
`
我一直在嘗試創建或打開一個檔案并在其中寫一些東西,但它似乎沒有做任何事情。
uj5u.com熱心網友回復:
這是關于密碼的。
但這里有一個方法:使用完整路徑。
例如:
from pathlib import Path
folder = Path(__file__).parent
your_txt = folder / "demofile3.txt"
with open(your_txt, "w") as f:
f.writelines(["\nSee you soon!", "\nOver and out."])
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/507186.html