Python 3.4 - How to Read and Write Files
You can create files in python in order to add data. To write to an existing or non-existing file you do the following:
This would open/ create the file and do whatever action we want to it, add text, and then close it.
You can do something similar for reading a file, but you need to add a string to ID the text you want to read:
https://www.youtube.com/watch?v=YV6qm6erphk
file = open('main.txt', 'w') file.write('Hello') file.close()
This would open/ create the file and do whatever action we want to it, add text, and then close it.
You can do something similar for reading a file, but you need to add a string to ID the text you want to read:
file2 = open('main.txt', 'r') text = file2.read() print(text) file2.close()
https://www.youtube.com/watch?v=YV6qm6erphk
Comments