最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

3種python調(diào)用其他腳本的方法

 更新時(shí)間:2020年01月06日 09:56:41   作者:python學(xué)習(xí)者0  
這篇文章主要介紹了3種python調(diào)用其他腳本的方法,每種方法通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

1.用python調(diào)用python腳本

#!/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')

另外一個(gè)python腳本b.py如下:

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

運(yùn)行結(jié)果:

[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調(diào)用shell方法os.system()

#!/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"

運(yùn)行結(jié)果:

[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調(diào)用shell方法os.popen()

#!/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')

運(yùn)行結(jié)果:

[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() 這個(gè)方法會(huì)打開一個(gè)管道,返回結(jié)果是一個(gè)連接管道的文件對(duì)象,該文件對(duì)象的操作方法同open(),可以從該文件對(duì)象中讀取返回結(jié)果。如果執(zhí)行成功,不會(huì)返回狀態(tài)碼,如果執(zhí)行失敗,則會(huì)將錯(cuò)誤信息輸出到stdout,并返回一個(gè)空字符串。這里官方也表示subprocess模塊已經(jīng)實(shí)現(xiàn)了更為強(qiáng)大的subprocess.Popen()方法。

總結(jié)

以上所述是小編給大家介紹的3種python調(diào)用其他腳本的方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!

相關(guān)文章

  • pytorch中常用的乘法運(yùn)算及相關(guān)的運(yùn)算符(@和*)

    pytorch中常用的乘法運(yùn)算及相關(guān)的運(yùn)算符(@和*)

    pytorch是深度學(xué)習(xí)框架,而深度學(xué)習(xí)其實(shí)本質(zhì)就是一大堆矩陣乘法,最后用來模擬一個(gè)高維擬合函數(shù),下面這篇文章主要給大家介紹了關(guān)于pytorch中常用的乘法運(yùn)算及相關(guān)的運(yùn)算符(@和*)的相關(guān)資料,需要的朋友可以參考下
    2022-01-01
  • python實(shí)現(xiàn)Oracle查詢分組的方法示例

    python實(shí)現(xiàn)Oracle查詢分組的方法示例

    這篇文章主要介紹了python實(shí)現(xiàn)Oracle查詢分組的方法,結(jié)合實(shí)例形式分析了python使用group by子句及having子句實(shí)現(xiàn)Oracle查詢分組的相關(guān)操作技巧,需要的朋友可以參考下
    2020-04-04
  • pandas實(shí)現(xiàn)對(duì)一列/多列進(jìn)行數(shù)據(jù)區(qū)間篩選

    pandas實(shí)現(xiàn)對(duì)一列/多列進(jìn)行數(shù)據(jù)區(qū)間篩選

    這篇文章主要介紹了pandas實(shí)現(xiàn)對(duì)一列/多列進(jìn)行數(shù)據(jù)區(qū)間篩選方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • Python接口自動(dòng)化之淺析requests模塊post請(qǐng)求

    Python接口自動(dòng)化之淺析requests模塊post請(qǐng)求

    這篇文章Python接口自動(dòng)化之淺析requests模塊post請(qǐng)求,以下主要介紹requests模塊中的post請(qǐng)求的使用,post源碼,data、json參數(shù)應(yīng)用場(chǎng)景及實(shí)戰(zhàn)
    2021-08-08
  • Python的凈值數(shù)據(jù)接口調(diào)用示例分享

    Python的凈值數(shù)據(jù)接口調(diào)用示例分享

    這篇文章主要介紹了Python的凈值數(shù)據(jù)接口調(diào)用示例分享的相關(guān)資料,需要的朋友可以參考下
    2016-03-03
  • python圖的深度優(yōu)先和廣度優(yōu)先算法實(shí)例分析

    python圖的深度優(yōu)先和廣度優(yōu)先算法實(shí)例分析

    這篇文章主要介紹了python圖的深度優(yōu)先和廣度優(yōu)先算法,結(jié)合實(shí)例形式分析了圖的深度優(yōu)先算法與廣度優(yōu)先算法相關(guān)概念、原理、實(shí)現(xiàn)技巧與操作注意事項(xiàng),需要的朋友可以參考下
    2019-10-10
  • Python基于BeautifulSoup爬取京東商品信息

    Python基于BeautifulSoup爬取京東商品信息

    這篇文章主要介紹了Python基于BeautifulSoup爬取京東商品信息,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-06-06
  • Python新手如何理解循環(huán)加載模塊

    Python新手如何理解循環(huán)加載模塊

    在本篇文章里小編給大家整理了關(guān)于Python新手如何理解循環(huán)加載模塊相關(guān)知識(shí)點(diǎn),有需要的朋友們可以學(xué)習(xí)下。
    2020-05-05
  • matplotlib subplots 調(diào)整子圖間矩的實(shí)例

    matplotlib subplots 調(diào)整子圖間矩的實(shí)例

    今天小編就為大家分享一篇matplotlib subplots 調(diào)整子圖間矩的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-05-05
  • python mysql斷開重連的實(shí)現(xiàn)方法

    python mysql斷開重連的實(shí)現(xiàn)方法

    這篇文章主要介紹了python mysql斷開重連的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07

最新評(píng)論

布拖县| 衡山县| 临江市| 驻马店市| 同仁县| 孝义市| 尼勒克县| 延长县| 河北区| 云龙县| 康平县| 台北县| 枝江市| 尼勒克县| 县级市| 饶阳县| 扶风县| 邹城市| 岱山县| 潞西市| 阿巴嘎旗| 岫岩| 兰州市| 诸暨市| 泸定县| 环江| 石屏县| 阜新市| 榆中县| 铁岭市| 镇平县| 江口县| 河东区| 颍上县| 翁源县| 图木舒克市| 女性| 山东省| 开远市| 伊通| 嫩江县|