相关疑难解决方法(0)

告诉Python将.txt文件保存到Windows和Mac上的某个目录

你如何告诉Python保存文本文件的位置?

例如,我的计算机正在运行桌面上的Python文件.我希望它将所有文本文件保存在我的文档文件夹中,而不是保存在桌面上.我如何在这样的脚本中执行此操作?

name_of_file = raw_input("What is the name of the file: ")
completeName = name_of_file + ".txt"
#Alter this line in any shape or form it is up to you.
file1 = open(completeName , "w")

toFile = raw_input("Write what you want into the field")

file1.write(toFile)

file1.close()
Run Code Online (Sandbox Code Playgroud)

python

42
推荐指数
5
解决办法
25万
查看次数

标签 统计

python ×1