我的问题可能重复,但我找不到答案。
如何从另一个 python 文件获取 python 文件。像这样的东西:
def fun_1 (arg):
...
...
fun_2 (arg):
...
...
#### MAIN ####
Source the file that contains the function `fun_2`
fun_1('hello')
最佳答案
规范的方法是将第一个文件变成 module并将其导入
到第二个文件中:
$ cat file1.py
def fun():
print('in fun1')
$ cat file2.py
import file1
file1.fun()
关于python - 从另一个 Python 文件获取 Python 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19655688/