python调用不同文件中的函数方法

1. 暂时添加文件路径到系统路径中:

import sys

sys.path.append('/Users/abcdefg/Documents/life/miscellaneous/python_function')

2. 加载相应的python文件:

import file1

3. file1.function1就可以了

需要注意的是: file1的名字不要与python现有的包名冲突!

参考:
https://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章