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

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