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

簡單了解python調用其他腳本方法實例

 更新時間:2020年03月26日 11:06:06   作者:Python熱愛者  
這篇文章主要介紹了簡單了解python調用其他腳本方法實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

1.用python調用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')

另外一個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()

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

#!/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(),可以從該文件對象中讀取返回結果。如果執(zhí)行成功,不會返回狀態(tài)碼,如果執(zhí)行失敗,則會將錯誤信息輸出到stdout,并返回一個空字符串。這里官方也表示subprocess模塊已經實現了更為強大的subprocess.Popen()方法。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • python刪除列表元素del,pop(),remove()及clear()

    python刪除列表元素del,pop(),remove()及clear()

    這篇文章主要介紹了python刪除列表元素del,pop(),remove()及clear(),列表元素能增加就可以刪除,這里要給大家介紹的是刪除列表元素,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-03-03
  • PIP和conda 更換國內安裝源的方法步驟

    PIP和conda 更換國內安裝源的方法步驟

    這篇文章主要介紹了PIP和conda 更換國內安裝源的方法步驟,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2020-09-09
  • Python利用pywin32實現自動操作電腦

    Python利用pywin32實現自動操作電腦

    在windows系統(tǒng)上,重復性的操作可以用Python腳本來完成,其中常用的模塊是win32gui、win32con、win32api,要使用這三個模塊需要先安裝pywin32。本文就為大家介紹了如何利用這些模塊實現自動操作電腦,感興趣的可以了解一下
    2022-11-11
  • python中os模塊和sys模塊的使用詳解

    python中os模塊和sys模塊的使用詳解

    本文主要介紹了python中os模塊和sys模塊的使用詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-03-03
  • Python代碼風格與編程習慣重要嗎?

    Python代碼風格與編程習慣重要嗎?

    實現高內聚,低耦合、結構清晰不臃腫、可讀性高、數據冗余性低、高復用、易擴展的代碼,并非易事.上到設計模式,下到某個類、方法、函數的構造.在這里我分享一下我自己的代碼設計,編寫風格,讓我們互相學習,需要的朋友可以參考下
    2021-06-06
  • python實現dict版圖遍歷示例

    python實現dict版圖遍歷示例

    這篇文章主要介紹了python實現dict版圖遍歷的示例,需要的朋友可以參考下
    2014-02-02
  • python簡單分割文件的方法

    python簡單分割文件的方法

    這篇文章主要介紹了python簡單分割文件的方法,涉及Python針對文件的讀取與寫入技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-07-07
  • Python獲取Windows桌面路徑的三種方法

    Python獲取Windows桌面路徑的三種方法

    在日常編程工作中,有時我們需要將文件或數據自動保存到用戶的桌面上以便于快速訪問,在 Windows 操作系統(tǒng)中,可以通過多種方式來獲取桌面路徑,本文將詳細介紹三種常用的方法,需要的朋友可以參考下
    2024-12-12
  • 對python中大文件的導入與導出方法詳解

    對python中大文件的導入與導出方法詳解

    今天小編就為大家分享一篇對python中大文件的導入與導出方法詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12
  • 怎么用Python識別手勢數字

    怎么用Python識別手勢數字

    今天給大家?guī)淼奈恼率窃趺从肞ython識別手勢數字,文中有非常詳細的圖文示例,對正在學習python的小伙伴們很有幫助,需要的朋友可以參考下
    2021-06-06

最新評論

米泉市| 招远市| 巩义市| 峨山| 兴城市| 宁德市| 水城县| 改则县| 庄浪县| 泸西县| 沿河| 梧州市| 西畴县| 双柏县| 南岸区| 项城市| 许昌县| 石渠县| 栾川县| 广西| 北海市| 漳州市| 奎屯市| 施秉县| 崇信县| 调兵山市| 河南省| 微博| 吕梁市| 贞丰县| 老河口市| 廉江市| 志丹县| 特克斯县| 华蓥市| 浦县| 汝城县| 铅山县| 同仁县| 贡嘎县| 临清市|