Created
February 4, 2019 18:18
-
-
Save Robofied/c9a93f1e24a30f03b457b19f781c3c33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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