File Pointer
Table of Contents All Chapters 1. File Pointer 2. File Pointer Methods ┬а ┬а ┬а2.1. tell() Method ┬а ┬а ┬а2.2. seek() Method ┬а Python Tutorial Python Introduction Identation & Comments Python Variable Python Data Type Python Operators Conditional Statements Python Loops Python String Python List Python Tuple Python Set Python Dictionary Python Function Python Classes and Objects Python Inheritance Python Polymorphism Python Iterators Python Modules File Handling File Pointer Hamburger Toggle Menu Table of Contents 1. File Pointer 2. File Pointer Methods ┬а ┬а ┬а2.1. tell() Method ┬а ┬а ┬а2.2. seek() Method File Pointerr in Hindi What is File Pointer in Python File pointer рдПрдХ position рд╣реЛрддрд╛ рд╣реИ, рдЬреЛ рд╣рдореЗ рджрд┐рдЦрд╛рддрд╛ рд╣реИ рдХрд┐ рд╣рдо file рдореЗрдВ рдХрд┐рд╕ рдЬрдЧрд╣ рдкрд░ рд╣реИ, python рдореЗрдВ by default рдпреЗ pointer рдХрд┐рд╕реА file рдХреЗ starting (рдпрд╛рдирд┐ 0 index) рдкрд░ рд╣реЛрддрд╛ рд╣реИред File Pointer Methods python рдореЗрдВ file pointer рдХреЗ position рдХреЗ рд▓рд┐рдП f.tell() рдФрд░ f.seek() functions рдХрд╛ use рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИред tell() Method tell() method рд╣рдореЗ file pointer рдХрд╛ current position рдмрддрд╛рддрд╛ рд╣реИред рдЬрдм file рдХреЛ open рдХрд┐рдпрд╛ рдЬрд╛рддрд╛ рд╣реИ рддреЛ pointer рдХрд╛ position 0 index (starting) рдкрд░ рд╣реЛрддрд╛ рд╣реИ, but рдЬрдм рд╣рдо file рдореЗрдВ рдХреБрдЫ read рдпрд╛ write рдХрд░рддреЗ рд╣реИ рддреЛ pointer move рд╣реЛ рдЬрд╛рддрд╛ рд╣реИ, рдРрд╕реЗ рдореЗрдВ рд╣рдо tell() method рдХрд╛ use рдХрд░рдХреЗ pointer рдХрд╛ current position рджреЗрдЦ рд╕рдХрддреЗ рд╣реИред ЁЯРН Example 1.py Copy to clipboard 1 2 3 4 f = open("demo.txt","r") print(f.read(5)) # first 5 characters read print("Pointer at:", f.tell()) # ab pointer position 5 pe hai f.close() seek() Method seek() method рдХрд╛ use рдХрд░рдХреЗ рд╣рдо pointer рдХреЛ рдХрд┐рд╕реА specific position рдкрд░ рд▓реЗ рдЬрд╛ рд╕рдХрддреЗ рд╣реИред рдЗрд╕рдореЗ 2 parameter рд╣реЛрддреЗ рд╣реИ- offset : рд╣рдореЗ pointer рдХреЛ file рдореЗрдВ рдХрд┐рддрдиреЗ bytes move рдХрд░рдирд╛ рд╣реИ рд╡реЛ argument (number) рд╣рдореЗ рдЗрд╕рдореЗ рджреЗрдВрдЧреЗред whence : рдпреЗ optional рд╣реЛрддрд╛ рд╣реИ рдЬрд┐рд╕рдХрд╛ by default value 0 рд╣реЛрддрд╛ рд╣реИ рдорддрд▓рдм pointer file рдореЗрдВ beginning рд╕реЗ move рд╣реЛрдЧрд╛ред рдЕрдЧрд░ рд╣рдо рдЗрд╕рдореЗ 1 рджреЗрдВрдЧреЗ рддреЛ pointer рдЕрдкрдиреЗ current position рд╕реЗ move рд╣реЛрдЧрд╛, рдФрд░ рдЕрдЧрд░ рд╣рдореЗ 2 рджреЗрдВрдЧреЗ рддреЛ pointer рдЙрд╕ file рдореЗрдВ end рд╕реЗ move рдХрд░реЗрдЧрд╛ред ЁЯРН Example 2.py Copy to clipboard 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 # File content: "HelloWorld" (10 characters) # whence = 0 (beginning of file) with open("demo.txt", "r") as f: f.seek(3, 0) # start se 3 characters aage – index=3 print("seek(3,0) position:", f.tell()) print("read(4):", f.read(4)) # "loWo" # whence = 1 (current position) with open("demo.txt", "r") as f: print("read(5):", f.read(5)) # "Hello"; pointer now at 5 f.seek(2, 1) # current position (5) + 2 – index=7 print("seek(2,1) position:", f.tell()) print("read(2):", f.read(2)) # "rl" # whence = 2 (end of file) with open("demo.txt", "rb") as f: # binary mode recommended f.seek(-4, 2) # end se 4 bytes peeche – index=6 print("seek(-4,2) position:", f.tell()) print("read():", f.read()) # b"orld" рдЙрдореНрдореАрдж рдХрд░рддреЗ рд╣реИ рдХрд┐ рдЖрдкрдХреЛ File Pointer рдЕрдЪреНрдЫреЗ рд╕рдордЭ рдореЗ рдЖ рдЧрдпрд╛ рд╣реЛрдЧрд╛ рдпреЗ рдПрдХ File Handling рдХрд╛ topic рд╣реИред рдЕрдкрдиреЗ learning рдХреЛ continue рд░рдЦрдиреЗ рдХреЗ рд▓рд┐рдП next button рдкрд░ click рдХрд░реЗ, Previous Next Add a comment… Cancel Reply Logged in as Python Programming Hub. Edit your profile. Log out? Required fields are marked * Message*