0% found this document useful (0 votes)
37 views8 pages

Seek and Tell Functions

..........

Uploaded by

smodi6545
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views8 pages

Seek and Tell Functions

..........

Uploaded by

smodi6545
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Random Access in Files

seek()
tell()
RECGRDED WiH
SCREENCAST MATIC
seek()
seek() function is used to change the position of the file
handle (file pointer) to a given specific position.
File pointer is like acursor, which defines from where the
data has to be read or written in the file.
Syntax :
f.seek(offset, from_what)
#where f is file pointer

RECGRDEO WiH
SCREENCASTO MATIC
seek()
The reference point is defined by the "from_what"
argument. It can have any of the three values:
0: sets the reference point at the beginning of the file,
which is by default.
1: sets the reference point at the current file position.
2: sets the reference point at the end of the file.
But, in Python 3.x and above, we can seek from
only, if openedin text mode. We can overcome
by opening the file in b mode.
RECORDED WiTH
SCREENCAST MATIC
seek()
The reference point is defined by the "from wha
argument. It can have any of the three values:
0: sets the reference point at the beginning of the file,
which is by default.
1: sets the reference point at the current file position.
2: sets the reference point at the end of the file.
But, in ython 3.x and above, we can seek from beginning
only, if opened in text mode. We can overcome from this
byopening the file in b mode.
RECGRDED WiTH
2007
34-05-208
ython i45 Sel
e fdt Shel Debug Csbona Window belp

RESTART: C:\Users\sony\AppData\Local\ Programs\Python\Python3 6-3


2\demo.py =
lo and Welcome to Python Programming Tutorial
>>>
RESTART: C:\Users\sony\AppData\Local\ Programs\Pyt
2\demo.py
lo and Welcome to Python Programming Tutorial
and Wel come to Python Programming Tutorial
>>>
=RESTART: C:\Users\sony\AppData\Local\ Programs\Python\Python36-3
2\demo.py =
lo and Welcome to Python Programming Tutorial
and Wel come to Python Programming Tutorial
Current location of pointer= 48
>>> I

SCREEICASTMATc 2013
2645-70
Fie Edt fomat un Ogtionu Window Hep

f=open ("Random. txt","r")


print (£. tell (0)
£. seek (3)
print(£.read())
£. 6)
print (£.read(O)
print ("Current location of pointer=" ,f. tell())

SCREEISTtC 2011
34-95-2039
te tat She Dbug pbons Wndow belp

lo and Welcome to Python Programming Tutorial


and Welcome to Python Programming Tutorial
>>>
==RESTART: C:\Users\ sony\AppData\Local\Programs\Python\Puthon36-3
2\demo.py
lo and Welcome to Python Programming Tutorial
and Welcome to Python Programming Tutorial
Current location of pointer= 48
>>>
= RESTART: C: \Users\sony\AppData\Local\ Programs\Python \Python36-3
2\demo.py =
lo and Welcome to Python Programming Tutorial
Current location of pointer= 11
>>>

SSREEIGSTMEO 2015
645-37
Le demagy-CUertaoryAppatakocat PrograPythonython-1Ndemopy(45
Fe tdt fomt un Ggtont Window Help

f=open ("Random. txt", "rb")


print (£. tell())
£. seek (3)
print(£.read())
E.seek (-6,11)
print (£.read(5) )
print ("Current location of pointer=",f.tel1())

SCREESISTMAC 2016
3445-03

You might also like