繁体   English   中英

无法在 python 中创建、打开、写入文件

[英]Can't create, open, write files in python

f = open("demofile3.txt", "w")
f.writelines(["\nSee you soon!", "\nOver and out."])
f.close()

`

我一直在尝试创建或打开一个文件并在其中写一些东西,但它似乎没有做任何事情。

这是关于密码的。

但这里有一个方法:使用完整路径。

例如:

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."])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM