中文字幕第五页-中文字幕第页-中文字幕韩国-中文字幕最新-国产尤物二区三区在线观看-国产尤物福利视频一区二区

3種python調用其他腳本的方法,你還知道其他的方法嗎?

1.用python調用python腳本

創新互聯建站長期為成百上千家客戶提供的網站建設服務,團隊從業經驗10年,關注不同地域、不同群體,并針對不同對象提供差異化的產品和服務;打造開放共贏平臺,與合作伙伴共同營造健康的互聯網生態環境。為內鄉企業提供專業的成都做網站、成都網站設計,內鄉網站改版等技術服務。擁有10多年豐富建站經驗和眾多成功案例,為您定制開發。

#!/usr/local/bin/python3.7
import time
import os 

count = 0
str = ('python b.py')
result1 = os.system(str)
print(result1)
while True:
    count = count + 1
    if count == 8:
      print('this count is:',count) 
      break
    else:
      time.sleep(1)
      print('this count is:',count)   

print('Good Bye')

另外一個python腳本b.py如下:

#!/usr/local/bin/python3.7
print('hello world')

運行結果:

[python@master2 while]$ python a.py 
hello world
this count is: 1
this count is: 2
this count is: 3
this count is: 4
this count is: 5
this count is: 6
this count is: 7
this count is: 8
Good Bye

2.python調用shell方法os.system()

'''
遇到問題沒人解答?小編創建了一個Python學習交流QQ群:579817333 
尋找有志同道合的小伙伴,互幫互助,群里還有不錯的視頻學習教程和PDF電子書!
'''
#!/usr/local/bin/python3.7
import time
import os 

count = 0
n = os.system('sh b.sh')
while True:
    count = count + 1
    if count == 8:
      print('this count is:',count) 
      break
    else:
      time.sleep(1)
      print('this count is:',count)   

print('Good Bye')

shell腳本如下:

#!/bin/sh
echo "hello world"

運行結果:

[python@master2 while]$ python a.py 
hello world
this count is: 1
this count is: 2
this count is: 3
this count is: 4
this count is: 5
this count is: 6
this count is: 7
this count is: 8
Good Bye

3.python調用shell方法os.popen()

'''
遇到問題沒人解答?小編創建了一個Python學習交流QQ群:579817333 
尋找有志同道合的小伙伴,互幫互助,群里還有不錯的視頻學習教程和PDF電子書!
'''
#!/usr/local/bin/python3.7
import time
import os 

count = 0
n = os.system('sh b.sh')
while True:
    count = count + 1
    if count == 8:
      print('this count is:',count) 
      break
    else:
      time.sleep(1)
      print('this count is:',count)   

print('Good Bye')

運行結果:

[python@master2 while]$ python a.py 
<os._wrap_close object at 0x7f7f89377940>
['hello world\n']
this count is: 1
this count is: 2
this count is: 3
this count is: 4
this count is: 5
this count is: 6
this count is: 7
this count is: 8
Good Bye

os.system.popen() 這個方法會打開一個管道,返回結果是一個連接管道的文件對象,該文件對象的操作方法同open(),可以從該文件對象中讀取返回結果。如果執行成功,不會返回狀態碼,如果執行失敗,則會將錯誤信息輸出到stdout,并返回一個空字符串。這里官方也表示subprocess模塊已經實現了更為強大的subprocess.Popen()方法。

文章題目:3種python調用其他腳本的方法,你還知道其他的方法嗎?
當前路徑:http://www.2m8n56k.cn/article6/ijccig.html

成都網站建設公司_創新互聯,為您提供網站設計商城網站虛擬主機網站排名App開發

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:[email protected]。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

微信小程序開發
主站蜘蛛池模板: 久草资源在线 | 亚洲香蕉一区二区三区在线观看 | 欧美在线视频免费观看 | 亚洲 欧美 国产 中文 | 亚洲第一页在线播放 | 亚洲www在线 | 欧美一级看片 | 全部在线美女网站免费观看 | 久久综合久久自在自线精品自 | 成人精品一区二区久久久 | 久久五月女厕所一区二区 | 国产精品欧美亚洲日本综合 | 国产精品一区二区三区久久 | 国产在线观看网址在线视频 | 日本在线视频播放 | 欧美在线一区二区 | 欧美一级网 | 亚洲一级毛片中文字幕 | 影院亚洲 | 91香蕉国产线在线观看免费 | 韩国毛片 | 2020国产成人免费视频 | 欧美另类高清xxxxx | 看欧美的一级毛片 | 成人毛片免费免费 | 亚洲午夜久久久久影院 | 久久99热久久精品91 | 蜜桃日本一道无卡不码高清 | 欧美一区二区三区视视频 | 欧美做a一级视频免费观看 欧美做爱毛片 | 精品国产一区二区三区免费 | 偷拍亚洲欧美 | 精品视频 久久久 | 国产黄色片在线观看 | 一个人看的免费观看日本视频www | 新版天堂资源中文8在线 | 真人真实毛片免费观看 | 女人十八一级毛片 | 在线免费精品视频 | 99精品福利视频在线一区 | 黄色毛片视频校园交易 |