欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

簡(jiǎn)單了解python調(diào)用其他腳本方法實(shí)例

 更新時(shí)間:2020年03月26日 11:06:06   作者:Python熱愛者  
這篇文章主要介紹了簡(jiǎn)單了解python調(diào)用其他腳本方法實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(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()方法。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python 二叉樹的層序建立與三種遍歷實(shí)現(xiàn)詳解

    Python 二叉樹的層序建立與三種遍歷實(shí)現(xiàn)詳解

    這篇文章主要介紹了Python 二叉樹的層序建立與三種遍歷實(shí)現(xiàn)詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-07-07
  • pytorch 實(shí)現(xiàn)tensor與numpy數(shù)組轉(zhuǎn)換

    pytorch 實(shí)現(xiàn)tensor與numpy數(shù)組轉(zhuǎn)換

    今天小編就為大家分享一篇使用pytorch 實(shí)現(xiàn)tensor與numpy數(shù)組轉(zhuǎn)換,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2019-12-12
  • 利用python和ffmpeg 批量將其他圖片轉(zhuǎn)換為.yuv格式的方法

    利用python和ffmpeg 批量將其他圖片轉(zhuǎn)換為.yuv格式的方法

    今天小編就為大家分享一篇利用python和ffmpeg 批量將其他圖片轉(zhuǎn)換為.yuv格式的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2019-01-01
  • python生成隨機(jī)紅包的實(shí)例寫法

    python生成隨機(jī)紅包的實(shí)例寫法

    在本篇文章里小編給大家整理的是關(guān)于python生成隨機(jī)紅包的實(shí)例寫法以及相關(guān)知識(shí)點(diǎn),有需要的朋友們可以學(xué)習(xí)下。
    2019-09-09
  • tensorflow-gpu安裝的常見問題及解決方案

    tensorflow-gpu安裝的常見問題及解決方案

    這篇文章主要介紹了tensorflow-gpu安裝的常見問題及解決方案,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧,需要的朋友可以參考下
    2020-01-01
  • Python中dilb和face_recognition第三方包安裝失敗的解決

    Python中dilb和face_recognition第三方包安裝失敗的解決

    本文主要介紹了Python中dilb和face_recognition第三方包安裝失敗的解決,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-02-02
  • tensorflow 只恢復(fù)部分模型參數(shù)的實(shí)例

    tensorflow 只恢復(fù)部分模型參數(shù)的實(shí)例

    今天小編就為大家分享一篇tensorflow 只恢復(fù)部分模型參數(shù)的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-01-01
  • python 單線程和異步協(xié)程工作方式解析

    python 單線程和異步協(xié)程工作方式解析

    這篇文章主要介紹了python 單線程和異步協(xié)程工作方式解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-09-09
  • pytorch中model.named_parameters()與model.parameters()解讀

    pytorch中model.named_parameters()與model.parameters()解讀

    這篇文章主要介紹了pytorch中model.named_parameters()與model.parameters()使用及說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-11-11
  • Python3.10的一些新特性原理分析

    Python3.10的一些新特性原理分析

    由于采用了新的發(fā)行計(jì)劃:PEP 602 -- Annual Release Cycle for Python,我們可以看到更短的開發(fā)窗口,我們有望在 2021 年 10 月使用今天分享的這些新特性
    2021-09-09

最新評(píng)論