How do you tell Python where to save a text file?
For example, my computer is running the Python file off my desktop. I want it to save all the text file in my docum
Just use an absolute path when opening the filehandle for writing.
import os.path
save_path = 'C:/example/'
name_of_file = raw_input("What is the name of the file: ")
completeName = os.path.join(save_path, name_of_file+".txt")
file1 = open(completeName, "w")
toFile = raw_input("Write what you want into the field")
file1.write(toFile)
file1.close()
You could optionally combine this with os.path.abspath() as described in Bryan's answer to automatically get the path of a user's Documents folder. Cheers!