Read and write any file

you can practically read and write into any file.

here are a few examples.

# Write into a file
with open("text.txt") as file:
    file.write("this line was written by a function")

# Read a file
with open("text.txt") as file:
    file_content = file.read()
    print(file_content) # this will print all the file content that has been read

Now, the file can be of any format, so go crazy with it.

know more about context managers

Updated on