Working with the file in Python

Working with the file in Python

Instructor-svgAl-Mamun Sarkar
Mar 25 , 2020

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()

 

  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram