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("test.txt",'w',encoding = 'utf-8') as f:
2 f.write("my first file\n")
3 f.write("This file\n\n")
4 f.write("contains three lines\n")
1path = "guide/README.txt" # The path of your file should go here
2with open(path, "w") as fil: # Opens the file using 'w' method. See below for list of methods.
3 fil.write("This is the README. It is reccomended that you read it.") # Writes to the file used .write() method
4 fil.close() # Closes file
5'''
6List of methods:
7w* - replace everything with needed text
8r^ - read the file
9a* - adds to file
10x - creates file
11
12* Creates file if the file at that path does not exist
13^ Throws error if file does not exist
14'''
15
1file = open("directory/sample.txt", "w")
2
3file.write(“Hello World”)
4
5file.close()
6
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")