1file = open("text.txt", "w")
2file.write("Your text goes here")
3file.close()
4'r' open for reading (default)
5'w' open for writing, truncating the file first
6'x' open for exclusive creation, failing if the file already exists
7'a' open for writing, appending to the end of the file if it exists
1file = open(“testfile.txt”,”w”)
2
3file.write(“Hello World”)
4file.write(“This is our new text file”)
5file.write(“and this is another line.”)
6file.write(“Why? Because we can.”)
7
8file.close()
1with open("testfile.txt", "w") as f:
2 # "w" - write into file
3 # "r" - read into file
4 # "+" - read and write into file
5 f.write("Hello World")
1import os
2
3newpath = r'C:\Program Files\arbitrary'
4if not os.path.exists(newpath):
5 os.makedirs(newpath)