About the Tutorial



Download 2,85 Mb.
Pdf ko'rish
bet199/234
Sana28.05.2022
Hajmi2,85 Mb.
#614232
1   ...   195   196   197   198   199   200   201   202   ...   234
Bog'liq
python3 tutorial 060821094426

Return Value 
This method returns an open file object connected to the pipe. 
Example 
The following example shows the usage of popen() method. 
# !/usr/bin/python3 
import os, sys 
# using command mkdir 
a = 'mkdir nwdir' 
b = os.popen(a,'r',1) 
print b 
When we run the above program, it produces the following result- 
open file 'mkdir nwdir', mode 'r' at 0x81614d0 
os.read() Method 
Description 
The method read() reads at most n bytes from file desciptor fd, return a string containing 
the bytes read. If the end of file referred to by fd has been reached, an empty string is 
returned. 
Note: This function is intended for low-level I/O and must be applied to a file descriptor 
as returned by os.open() or pipe(). To read a “file object” returned by the built-in function 
open() or by popen() or fdopen(), or sys.stdin, use its read() or readline() methods. 
Syntax 
Following is the syntax for read() method- 
os.read(fd,n) 
Parameters 

fd
- This is the file descriptor of the file. 

n
- These are n bytes from file descriptor fd. 


Python 3 
299 
Return Value 
This method returns a string containing the bytes read. 
Example 
The following example shows the usage of read() method. 
# !/usr/bin/python3 
import os, sys 
# Open a file 
fd = os.open("foo.txt",os.O_RDWR) 
# Reading text 
ret = os.read(fd,12) 
print (ret.decode()) 
# Close opened file 
os.close(fd) 
print ("Closed the file successfully!!") 
Let us compile and run the above program, this will print the contents of file foo.txt- 
This is test 
Closed the file successfully!! 
os.readlink() Method 

Download 2,85 Mb.

Do'stlaringiz bilan baham:
1   ...   195   196   197   198   199   200   201   202   ...   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