在Python中调用其他Python脚本主要有以下几种方法:
1. 使用`os.system()`函数:
import os
os.system('python b.py')
2. 使用`import`语句导入脚本或模块,然后调用其中的函数、类或变量:
import script2
script2.my_function()
3. 使用`subprocess`模块调用其他脚本:
import subprocess
subprocess.run(['python', 'b.py'])
4. 使用`execfile()`函数(不推荐,因为`execfile()`在Python 3中已被移除):
execfile('b.py')
5. 使用`importlib`模块动态导入脚本:
import importlib
import b
b.my_function()
请根据您的具体需求选择合适的方法。