开发者

importing from higher directories in python [duplicate]

开发者 https://www.devze.com 2023-01-25 09:22 出处:网络
This question already开发者_开发知识库 has answers here: Closed 11 years ago. Possible Duplicate:
This question already开发者_开发知识库 has answers here: Closed 11 years ago.

Possible Duplicate:

How to do relative imports in Python?

How do I import from a higher level directory in python.

For example:

I have project/lib/lib.py project/stuff/main.py

i want to import lib.py in main.py

Thanks in advance


You can do it like:

from ..lib import lib


standard method is to add project to your path and do

import lib.lib

You will need a file called __init__.py in the lib folder as well, which can be blank.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号