If you are running a script in the folder a, I would like to get the absolute path of c.py in the folder b in the same hierarchy as a in that script.
For example, a and b are in the same folder named d.python
It's solved.We actually used os.path.dirname to specify the upper hierarchy.
_init__.py must be placed in order to
import anything below the b folder.
_init__.py should be empty.
You can specify where this file is located in
a/ ├ ├ hoge.py └ b/ ├ __init__.py └ └ c.py
from b.import something something()
def something(): print('test')
By the way, the
import method can also be
However, if you import it that way, it must be
b.c.something() when calling the method.
Class definitions can also be invoked.
from b.import something, TestClass something() test_class = TestClass() test_class.something()
def something(): print('test') class TestClass(): def__init__(self): pass def something (self): print('class test')
Check the documentation for details.
© 2023 OneMinuteCode. All rights reserved.