简单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
['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
os.system.popen() 这个方法会打开一个管道,返回结果是一个连接管道的文件对象,该文件对象的操作方法同open(),可以从该文件对象中读取返回结果。如果执行成功,不会返回状态码,如果执行失败,则会将错误信息输出到stdout,并返回一个空字符串。这里官方也表示subprocess模块已经实现了更为强大的subprocess.Popen()方法。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
简单python脚本实例-简单了解python调用其他脚本方法实例相关推荐
- python子类继承父类属性实例_Python实现子类调用父类的初始化实例
前言 python中进行面向对象编程,当在子类的实例中调用父类的属性时,由于子类的__init__方法重写了父类的__init__方法,如果在子类中这些属性未经过初始化,使用时就会出错. 例如以下的代 ...
- halcon可以用python吗_如何基于pythonnet调用halcon脚本
这篇文章主要介绍了如何基于pythonnet调用halcon脚本,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 最近的项目中遇到了使用python程 ...
- halcon python 联合开发_使用pythonnet调用halcon脚本
最近的项目中遇到了使用python程序结合不同部分,其中包括使用halcon处理拍摄到的图像. halcon本身提供了c++与.NET的开发库,但无python库,网上有pyhalcon之类的库,但功 ...
- python程序实例讲解_Python编程之属性和方法实例详解
本文实例讲述了Python编程中属性和方法使用技巧.分享给大家供大家参考.具体分析如下: 一.属性 在python中,属性分为公有属性和私有属性,公有属性可以在类的外部调用,私有属性不能在类的外部调用 ...
- python json转换字典_Python json转字典字符方法实例解析
josn基本操作 1.导入import json 2.字典转json:json.dumps(dict,ensure_ascii=False),加,ensure_ascii=False转换之后无中文乱码 ...
- python中copytree的用法_python复制文件的方法实例详解
本文实例讲述了python复制文件的方法.分享给大家供大家参考.具体分析如下: 这里涉及Python复制文件在实际操作方案中的实际应用以及Python复制文件 的相关代码说明,希望你会有所收获. Py ...
- python selenium翻页_Selenium翻页的实现方法实例
在实际测试项目中,会出现新增数据记录不显示在第一页,而是显示最后一页,对于这种情况,那我们要根据每页显示数据数来进行翻页,保证代码能够准确拿到数据文本来做结果比对. 第一步:在基础类BaseTest中 ...
- java如何调用父类的实例对象_java子类调用父类的方法中包含子类重写的实例方法...
java子类调用父类的方法中包含子类重写的实例方法 # 看题目是不是很绕,这个我也不知道怎么才能更简单的表达了 # 先看代码: public class Common { public static ...
- hive运行mysql脚本_用java代码调用shell脚本执行sqoop将hive表中数据导出到mysql
1:创建shell脚本 1 touch sqoop_options.sh2 chmod 777 sqoop_options.sh 编辑文件 特地将执行map的个数设置为变量 测试 可以java代码 ...
- python打印长方形_利用python打印出菱形、三角形以及矩形的方法实例
前言 本文主要给大家介绍了关于利用python打印出菱形.三角形以及矩形的相关内容,分享出来供大家参考学习,话不多说,来一起看看详细的介绍: 实例代码 #coding:utf-8 rows = int ...
最新文章
- R语言如何画个性化词云图
- 【每天一个linux命令】read
- 回归素材(part1)--实用机器学习
- Android开发学习笔记:浅谈Content Provider
- C++:unordered_map
- php如何根据ip查找地址,根据IP地址查找IP所在地
- Windows 与 Linux 通过Xshell 文件互传
- SQLPrompt 安装后sql上看不到菜单
- C语言连接Oracle数据库
- java计算机毕业设计辅导员班级量化管理系统MyBatis+系统+LW文档+源码+调试部署
- SmartSVN for Mac(SVN客户端)
- matlab解反应扩散方程,反应扩散方程Matlab编程
- 【关系模型相关概念】小楼一夜听春雨——数据库学习之路(3)
- 国内外php商城系统 开源
- 什么是SDK? SDK是什么意思?
- 如何通过 6 个简单步骤在百度上看到您的网站
- 计算任意文件夹大小 , 校验大文件的一致性 , 发抢红包程序
- mc服务器地皮系统权限指令,我的世界地皮指令大全
- netcat基本使用方法总结
- WPF 入门教程Grid使用技巧