Easy Tutorial
❮ Python Att Time Mktime Python Xml Processing ❯

Python File IO

Python3 Examples

The following code demonstrates basic file operations in Python, including open, read, and write:

Example (Python 3.0+)

# Filename : test.py
# author by : www.tutorialpro.org

# Write to a file
with open("test.txt", "wt") as out_file:
    out_file.write("This text will be written to the file\nSee me now!")

# Read from a file
with open("test.txt", "rt") as in_file:
    text = in_file.read()

print(text)

Executing the above code outputs the following result:

This text will be written to the file
See me now!

Python3 Examples

❮ Python Att Time Mktime Python Xml Processing ❯