[Structure]
Root
|_ app
|_util
|_ log.py
|_config.py
|_ run.py
[run.py]
#import sys
#import os
#sys.path.insert(0, os.path.abspath('.'))
from app.config import Config
class App(object):
def __init__(self):
pass
def run(self):
Config.set_code(200)
Config.print_code()
if __name__ == '__main__':
app = App()
app.run()
[config.py]
from app.util.log import Log
class Config(object):
code = None
def __init__(self):
pass
@classmethod
def set_code(cls, code):
cls.code = code
@classmethod
def get_code(cls):
return cls.code
@classmethod
def print_code(cls):
Log.msg()
[log.py]
from app.config import Config
class Log(object):
def __init__(self):
pass
@classmethod
def msg(cls):
code = Config.get_code()
print('Code is: %r' % code)
[Current Output]
File "C:\works\workout\tmp\app\util\log.py", line 1, in <module>
from app.config import Config
ImportError: cannot import name 'Config' from 'app.config' (C:\works\workout\tmp\app\config.py)
[Expected Output]
Code is: 200
Another one doubt, is there any way we can fix root import as 'app', then whatever inside this folder/sub folder files (any kind of depth) access by,
[app/sub1/a.py]
from app.util.xx import XX
**from app.a import A**
from app.aaa.bb import BB
A.some_fn()
[app/a.py]
from app.util.xx import XX
**from app.sub1.a import A**
from app.aaa.bb import BB
A.some_fn()
[app/sub1/sub2/a.py]
**from app.sub1.a import A**
**from app.sub1.sub2.b import B**
from app.aaa.bb import BB
A.some_fn()
If any suggestions or ideas, then please! Thanks in advance,