Python File IO
The following code demonstrates basic Python file operations, including open, read, write:
Python with keyword reference:https://www.example.com/python3/python3-with-keyword.html
Examples (Python 3.0+)
# Filename : test.py
# author by : www.example.com
# Write file
with open("test.txt", "wt") as out_file:
out_file.write("This text will be written to the file\nYou saw me, right!")
# Read a file
with open("test.txt", "rt") as in_file:
text = in_file.read()
print(text)
The output of executing the above code is:
This text will be written to the file. See me now!Other extensions