1.自定义模块的调用
from backend.logic import handle handle.home()
2.上层模块的调用
import os import sys print(__file__) print(os.path.abspath(__file__)) print(os.path.dirname(os.path.abspath(__file__))) base_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.append(base_dir) print(sys.path) $ python path.py path.py /Users/guoxianqi/tmp/path.py /Users/guoxianqi/tmp [‘/Users/guoxianqi/tmp‘, ‘/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip‘, ‘/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7‘, ‘/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin‘, ‘/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac‘, ‘/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages‘, ‘/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python‘, ‘/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk‘, ‘/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old‘, ‘/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload‘, ‘/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC‘, ‘/Library/Python/2.7/site-packages‘, ‘/Users/guoxianqi/tmp‘]
时间: 2024-11-10 18:11:14