Python导入从上面的目录 [英] Python Imports From The Directory Above
问题描述
\main
\handlers
base.py
__init__.py
\users
__init__.py
authenticated.py
logout.py
我的问题是无法在用户文件夹中的任何文件中导入基数,但可以从用户文件夹导入。我知道我必须做一些像bellow这样的事情。
from ..handlers import *
但是,由于某些原因我无法做到这一点,所以我想要做的是将base.py导入到users目录中的文件和我添加的其他目录稍后的日期。
import sys
sys.path.append '/你/ dir /去/这里')
从基本的import foo
这应该允许您从您选择的任何目录导入东西。
I have a directory structure for my python application where in the main folder I have a folder called handlers and in that file I have a base.py that all handlers should inherit from . I also have a folder called users that contains all the handlers relating to users.
\main
\handlers
base.py
__init__.py
\users
__init__.py
authenticated.py
logout.py
My issue is I can't import the base in any file in the users folder but can import from the users folder. I know that I have to do something like bellow
from ..handlers import *
But that does not work for some reason all I am trying to do is import base.py into files in the users directory and other directorys I add at a later date.
import sys
sys.path.append('/your/dir/goes/here')
from base import foo
Something like that should permit you to import stuff from any directory of your choosing.
这篇关于Python导入从上面的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!