Question about sub-packages
frank at chagford.com
Tue Feb 28 13:44:48 CET 2012
"Frank Millman" <frank at chagford.com> wrote in message
news:jii0vo$36t$1 at dough.gmane.org...
> Hi all
> This is a follow-up to my recent question about circular imports, but on a
> different subject, hence the new thread.
> If this makes sense, my next thought was, where is the best place to put
> this API. Then I thought, why not put it in the __init__.py of the
> sub-package? Then all that the users of the package have to do is import
> the package, and then place calls on it directly.
> I did a quick test and it seems to work. Is this a good idea, or are there
> any downsides?
Answering my own question again ...
The one-liner API concept *may* be a good idea - still waiting for some
feedback on that.
But putting them into __init__.py is not a good idea, as I run into some
subtle 'circular import' problems again. I don't fully understand the
conditions under which it fails, but that is unimportant, as my objective is
to avoid circular imports altogether.
I have created a module called 'api.py' and put them in there, and that
seems to work (for now...).
More information about the Python-list