Geek Culture
Published in

Geek Culture

File Handling In Python

How to Read, Write, and Append a Python File?

File Handling: Python Tutorial Series

File Handling

a = open(file_name, access_mode)
a = open(file_name, 'r')
Read a file in Python
a = open('filename', 'w')
>>> c = open('newfile.txt', 'w') #it will create a new file in the             directory
>>> c.write("I write articles on Medium.")
write a file in python
a = open('filename', 'a')
Append a file in Python
>>> a = open('ONE.txt', 'r')
>>> b = open('TWO.txt', 'w')
>>> data = a.read()
>>> b.write(data)
>>> a.close()
>>> b.close()

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store