About the Tutorial



Download 2,85 Mb.
Pdf ko'rish
bet164/234
Sana28.05.2022
Hajmi2,85 Mb.
#614232
1   ...   160   161   162   163   164   165   166   167   ...   234
Bog'liq
python3 tutorial 060821094426

File truncate() Method 
Description 
The method 
truncate()
truncates the file's size. If the optional size argument is present, 
the file is truncated to (at most) that size. 
The size defaults to the current position. The current file position is not changed. Note that 
if a specified size exceeds the file's current size, the result is platform-dependent. 
Note
: This method will not work in case the file is opened in read-only mode. 
Syntax 
Following is the syntax for truncate() method- 
fileObject.truncate( [ size ]) 
Parameters 
size
- If this optional argument is present, the file is truncated to (at most) that size. 
Return Value 
This method does not return any value. 
Example 
The following example shows the usage of truncate() method. 
Assuming that 'foo.txt' file contains following text: 
This is 1st line 
This is 2nd line 
This is 3rd line 
This is 4th line 
This is 5th line 


Python 3 
238 
#!/usr/bin/python3 
fo = open("foo.txt", "r+") 
print ("Name of the file: ", fo.name) 
line = fo.readline() 
print ("Read Line: %s" % (line)) 
fo.truncate() 
line = fo.readlines() 
print ("Read Line: %s" % (line)) 
# Close opened file 
fo.close() 
When we run the above program, it produces the following result- 
Name of the file: foo.txt 
Read Line: This is 1s 
Read Line: [] 
File write() Method 
Description 
The method 
write()
writes a string str to the file. There is no return value. Due to 
buffering, the string may not actually show up in the file until the flush() or close() method 
is called. 
Syntax 
Following is the syntax for write() method- 
fileObject.write( str ) 

Download 2,85 Mb.

Do'stlaringiz bilan baham:
1   ...   160   161   162   163   164   165   166   167   ...   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