Skip to content

Instantly share code, notes, and snippets.

@Robofied
Created February 4, 2019 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Robofied/c9a93f1e24a30f03b457b19f781c3c33 to your computer and use it in GitHub Desktop.
Save Robofied/c9a93f1e24a30f03b457b19f781c3c33 to your computer and use it in GitHub Desktop.
## with simply open() method, we are trying to open the file and modify it.
## Created one file already in my cwd. If you want to fetch from other directory, just ## pass the path
file = open('file1.txt','r')
## It will print the file object.
print(file)
#[Output]:
<_io.TextIOWrapper name='file1.txt' mode='r' encoding='cp1252'>
## read()-> It will print all the lines/contents with new line character.
file.read()
#[Output]:
'1. "My name is XYZ".n2. "Currently I am persuing Bachelor's of Technology".n3. "I have done several projects on Software Development".'
## Here we have to close the file otherwise in large program it might create a proble.
## That's the reason, to open file with "with" keyword. Let's see how.
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment