About the Tutorial



Download 2,85 Mb.
Pdf ko'rish
bet185/234
Sana28.05.2022
Hajmi2,85 Mb.
#614232
1   ...   181   182   183   184   185   186   187   188   ...   234
Bog'liq
python3 tutorial 060821094426

Return Value 
This method does not return any value. Available on Unix like systems. 
Example 


Python 3 
274 
The following example shows the usage of ftruncate() method. 
#!/usr/bin/python3 
import os, sys 
# Open a file 
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) 
# Write one string 
os.write(fd, "This is test - This is test") 
# Now you can use ftruncate() method. 
os.ftruncate(fd, 10) 
# Now read this file from the beginning. 
os.lseek(fd, 0, 0) 
str = os.read(fd, 100) 
print ("Read String is : ", str) 
# 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 te 
Closed the file successfully!! 
os.getcwd() Method 
Description 
The method getcwd() returns current working directory of a process. 
Syntax 
Following is the syntax for getcwd() method- 
os.ggetcwd(path) 
Parameters 
NA 


Python 3 
275 
Return Value 
This method returns the current working directory of a process. 
Example 
The following example shows the usage of getcwd() method- 
#!/usr/bin/python3 
import os, sys 
# First go to the "/var/www/html" directory 
os.chdir("/var/www/html" ) 
# Print current working directory 
print ("Current working dir : %s" % os.getcwd()) 
# Now open a directory "/tmp" 
fd = os.open( "/tmp", os.O_RDONLY ) 
# Use os.fchdir() method to change the dir 
os.fchdir(fd) 
# Print current working directory 
print ("Current working dir : %s" % os.getcwd()) 
# Close opened directory. 
os.close( fd ) 
When we run the above program, it produces the following result- 
Current working dir : /var/www/html 
Current working dir : /tmp 

Download 2,85 Mb.

Do'stlaringiz bilan baham:
1   ...   181   182   183   184   185   186   187   188   ...   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