About the Tutorial



Download 2,85 Mb.
Pdf ko'rish
bet190/234
Sana28.05.2022
Hajmi2,85 Mb.
#614232
1   ...   186   187   188   189   190   191   192   193   ...   234
Bog'liq
python3 tutorial 060821094426

os.lseek() Method 
Description 
The method lseek() sets the current position of file descriptor fd to the given position pos, 
modified by how. 


Python 3 
283 
Syntax 
Following is the syntax for lseek() method- 
os.lseek(fd, pos, how) 
Parameters 

fd
- This is the file descriptor, which needs to be processed. 

pos
- This is the position in the file with respect to given parameter how. You give 
os.SEEK_SET or 0 to set the position relative to the beginning of the file, 
os.SEEK_CUR or 1 to set it relative to the current position; os.SEEK_END or 2 to 
set it relative to the end of the file. 

how
- This is the reference point with-in the file. os.SEEK_SET or 0 means 
beginning of the file, os.SEEK_CUR or 1 means the current position and 
os.SEEK_END or 2 means end of the file. 
Defined 
pos
constants 

os.SEEK_SET - 0 

os.SEEK_CUR - 1 

os.SEEK_END - 2 
Return Value 
This method does not return any value. 
Example 
The following example shows the usage of lseek() method. 
#!/usr/bin/python3 
import os, sys 
# Open a file 
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) 
# Write one string 
line="This is test" 
b=line.encode() 
os.write(fd, b) 
# Now you can use fsync() method. 
# Infact here you would not be able to see its effect. 
os.fsync(fd) 
# Now read this file from the beginning 
os.lseek(fd, 0, 0) 


Python 3 
284 
line = os.read(fd, 100) 
print ("Read String is : ", line.decode()) 
# Close opened file 
os.close( fd ) 
print "Closed the file successfully!!" 
When we run the above program, it produces the following result- 
Read String is : This is test 
Closed the file successfully!! 

Download 2,85 Mb.

Do'stlaringiz bilan baham:
1   ...   186   187   188   189   190   191   192   193   ...   234




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish