Domanda

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.

È stato utile?

Soluzione

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
         /...
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top