Skip to content

Instantly share code, notes, and snippets.

@Robofied
Last active February 4, 2019 19:04
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/abfc415327c48dc05e11e539c5fbad6e to your computer and use it in GitHub Desktop.
Save Robofied/abfc415327c48dc05e11e539c5fbad6e to your computer and use it in GitHub Desktop.
with open('file1.txt','r') as f:
## It will print each line and make the pointer to point at next line.
print(f.readline())
## It is telling the current position of the pointer
print(f.tell())
## Using seek we can modify the current pointer by passing the position as paramter in seek.
f.seek(0)
## Checking if pointer comes to 0 or not.
print(f.tell())
## Printing out the line again to check what will it prints.
print(f.readline())
#[Output]:
1. "My name is XYZ".
2
1
0
1. "My name is XYZ".
with open('file1.txt','r') as f:
print(f.readlines())
#[Output]:
['1. "My name is XYZ".n', '2. "Currently I am persuing Bachelor's of Technology".n', '3. "I have done several projects on Software Development".']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment