Simple File Reading and Writing in Python


Read from and write to files simply.

Source Code

# Write to a file
with open('myfile.txt', 'w') as f:
    f.write("Hello, file!")

# Read from a file
with open('myfile.txt', 'r') as f:
    content = f.read()
    print(content)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments