About the Tutorial



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

Return Value 
This method returns a pair of file descriptors. 
Example 
The following example shows the usage of pipe() method. 
#!/usr/bin/python3 
import os, sys 
print ("The child will write text to a pipe and ") 
print ("the parent will read the text written by child...") 
# file descriptors r, w for reading and writing 
r, w = os.pipe()
processid = os.fork() 
if processid: 
# This is the parent process
# Closes file descriptor w 
os.close(w) 
r = os.fdopen(r) 
print ("Parent reading") 


Python 3 
297 
str = r.read() 
print ("text =", str ) 
sys.exit(0) 
else: 
# This is the child process 
os.close(r) 
w = os.fdopen(w, 'w') 
print ("Child writing") 
w.write("Text written by child...") 
w.close() 
print ("Child closing") 
sys.exit(0) 
When we run the above program, it produces the following result- 
The child will write text to a pipe and 
the parent will read the text written by child... 
Parent reading 
Child writing 
Child closing 
text = Text written by child... 
os.popen() Method 
Description 
The method popen() opens a pipe to or from command.The return value is an open file 
object connected to the pipe, which can be read or written depending on whether mode is 
'r' (default) or 'w'.The bufsize argument has the same meaning as in open() function. 
Syntax 
Following is the syntax for popen() method- 
os.popen(command[, mode[, bufsize]]) 
Parameters 

command
- This is command used. 

mode
- This is the Mode can be 'r'(default) or 'w'. 


Python 3 
298 

bufsize
- If the buffering value is set to 0, no buffering will take place. If the 
buffering value is 1, line buffering will be performed while accessing a file. If you 
specify the buffering value as an integer greater than 1, then buffering action will 
be performed with the indicated buffer size. If negative, the buffer size is the 
system default(default behavior). 

Download 2,85 Mb.

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