문제

I'm working on this kind of structure por a project in python:

 main.py      #must get all the classes from /handlers
 jhpy.py
 handlers/    #files must import jhpy without making meth code in the a, b, ... files
         /a.py
         /b.py
         /...
 entities/    # files in handlers may need these. foo, bar, ... must import jhpy without making creepy code
         /foo.py
         /bar.py
         /...

The main goal is to make all of these mentioned things work, without having to do sys.blah blah in every single file. Point being, do not let a, b, foo, bar, ... have such horrible code.

Any ideas? I'm pretty sure I'd have to do more files. Perhaps I will need to add the __init__.py, if so, what should I write in these files? These "extra" files should do the dirty work, so that when I add new files to the /handlers and /entities they remain clean.

도움이 되었습니까?

해결책

All directories you want to use as modules should include a file named init.py

Your project structure would look like:

main.py      #must get all the classes from /handlers
jhpy.py
handlers/  
         /__init__.py
         /a.py
         /b.py
         /...
 entities/   
         /__init__.py
         /foo.py
         /bar.py
         /...
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top