aasthan4 / autogen

Automatic Expression Generator Code using Wicks theorem for Quantum Chemical Theories
5 stars 1 forks source link

How to generate a better package structure? #6

Open aasthan4 opened 6 years ago

aasthan4 commented 6 years ago

If I import a file main_tools/commutator.py in input file (main directory)

Is there a way to use the functions cleanly like comm() instead of c.omm().

(Refer to input.py in home directory.)

cs-shadow commented 6 years ago

Sorry, I missed this somehow. But the answer is yes!

Simple solution: Instead of doing from main_tools import commutator you can do something like from main_tools.commutator import comm and then you can use comm directly.

Better solution: Add a __init__.py in the main_tools directory, which will describe what parts of main_tools are considered to be safe for importing, i.e. what's public and what's private. For example, if you do the same thing in main_tools/__init__.py, then you'd be able to say from main_tools import comm.

I can't seem to find a good reference for __init__.py at the moment but http://mikegrouchy.com/blog/2012/05/be-pythonic-__init__py.html should get you started.

aasthan4 commented 6 years ago

Yo!! It works like a charm.