how to import py file from different upper folder?
All,
File structure:
\
util
utils.py
modules
__init__.py
modules1.py
submodule
__init__.py
submodule.py
I want to know how to import utils.py
in those
__init__.py
for example, now I run the python interpreter in \ level, I run import modules
, I suppose the code from ..util.utils import *
开发者_C百科may works, but it is not.
may I know where is the mistake? and may I know if there's a way i can import utils.py in a universal format? something like
import \util\utils.py
I know I may use path.append(), but any alternative?
Thanks
============
got the answer from this post:
Import a module from a relative path
If you are developping a python package (what you are obviously doing, as you have init.py), then the most simple way to import your module is just via the package.
For example, if your package is called mypackage
, then:
import mypackage.utils
精彩评论