Skip to main content
 首页 » 编程设计

python之树莓派 : How To Run A Python File From another file

2025年05月04日9arxive

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

A.py

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

B.py

  x = 0 
  while x < 10 
      print "B is running" 

答案必须像

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运行不必同步

请您参考如下方法:

import subprocess 
count = 1 
while True: 
    count+=1 
    if(count%20 == 0): 
         subprocess.Popen("python B.py") 
    print ("A is running")