怎么通过一个py文件访问另外一个py文件
2017-08-14 · 知道合伙人互联网行家
关注
展开全部
最简单的方法:
import <a href="https://www.baidu.com/s?wd=os&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YzPjmkmHTLujPhuH7Wuyw-0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHnLnHRvrjR3" target="_blank" class="baidu-highlight">os</a>
<a href="https://www.baidu.com/s?wd=os&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YzPjmkmHTLujPhuH7Wuyw-0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHnLnHRvrjR3" target="_blank" class="baidu-highlight">os</a>.system("python filename")
filename最好是全路径+文件名;
其他方法:
execfile('xx.py'),括号内为py文件路径;
如果需要传参数,就用os.system()那种方法;
如果还想获得这个文件的输出,那就得用os.popen();
import <a href="https://www.baidu.com/s?wd=os&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YzPjmkmHTLujPhuH7Wuyw-0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHnLnHRvrjR3" target="_blank" class="baidu-highlight">os</a>
<a href="https://www.baidu.com/s?wd=os&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YzPjmkmHTLujPhuH7Wuyw-0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EnHnLnHRvrjR3" target="_blank" class="baidu-highlight">os</a>.system("python filename")
filename最好是全路径+文件名;
其他方法:
execfile('xx.py'),括号内为py文件路径;
如果需要传参数,就用os.system()那种方法;
如果还想获得这个文件的输出,那就得用os.popen();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询