简体   繁体   English

如何在命令行中从另一个 python 脚本调用 Python 脚本?

[英]How to call a Python script in command line from another python script?

I have two python scripts, which need two different python versions (3.6 or older and 3.8 or newer).我有两个 python 脚本,它们需要两个不同的 python 版本(3.6 或更早版本和 3.8 或更新版本)。 To get the information produced from the older versioned script, I want to call it in the newer script on command line and save the results to a file, so that I can use it in the newer Script.要获取从旧版本脚本生成的信息,我想在命令行的新脚本中调用它并将结果保存到文件中,以便我可以在新脚本中使用它。

What's the best way to call my older script on command line from the newer one?从新脚本在命令行上调用旧脚本的最佳方式是什么?

You could use the os librar to run it.您可以使用 os librar 来运行它。

import os
os.system("py example.py")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM