树莓派:如何从另一个文件中运行Python文件

2024-04-26 13:51:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个python代码在运行(A.py),当python代码到达某个特定点时,我必须运行(B.py),而A.py仍在后台运行

A.py

count = 1
while True:
    count++
    if(count%20 == 0)
         //run b
    print "A is running"

B.py公司

^{pr2}$

答案必须是

A is running A is running ... 46 times repeat A is running A is running A is running B is running B is running A is running B is running A is running

A和b运行不需要同步


Tags: run答案代码pytrueifiscount
2条回答
if(count%20 == 0):
    execfile('B.py')
import subprocess
count = 1
while True:
    count+=1
    if(count%20 == 0):
         subprocess.Popen("python B.py")
    print ("A is running")

相关问题 更多 >