Working with the file in Python

Author: Al-mamun Sarkar Date: 2020-03-25 15:59:12

Working with the file in Python programming language. Following code shows how to open, read and write to file using python.

my_file = open('test.txt', 'w')
my_file.write('I am Al Mamun Sarkar')
my_file.close()

my_file = open('test.txt', 'a')
my_file.write('I am from Bangladesh.')
my_file.close()

my_file = open('test.txt', 'r')
content = my_file.read(5)
print(content)
content = my_file.read()
print(content)
position = my_file.tell()
print(position)
my_file.seek(0, 0)
content = my_file.read()
print(content)
my_file.close()