你如何告诉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 ×1