Module/package hierarchy and its separation from file structure
bignose+hates-spam at benfinney.id.au
Sun Jan 27 00:47:52 CET 2008
Carl Banks <pavlovevidence at gmail.com> writes:
> On Jan 25, 6:45 pm, Ben Finney <bignose+hates-s... at benfinney.id.au>
> > "Gabriel Genellina" <gagsl-... at yahoo.com.ar> writes:
> > > You can also put, in animal/__init__.py:
> > > from monkey import Monkey
> > > and now you can refer to it as org.lib.animal.Monkey, but keep the
> > > implementation of Monkey class and all related stuff into
> > > .../animal/monkey.py
> > This (as far as I can understand) is exactly the solution the
> > original poster desired to "shoot down", for reasons I still don't
> > understand.
> The solution is to modify the class's __module__ attribute as well as
> importing it, as I've already pointed out:
> from org.lib.animal.monkey import Monkey
> Monkey.__module__ = 'org.lib.animal'
Thanks, that makes it clear.
> This should be enough to satisfy the OP's requirements, at least for
> classes, without softening the one-to-one module-to-file
> relationship, or using "hacks".
> In fact, I'd say this is good practice.
I've not seen that before, but it seems an elegant way to address what
the OP is asking for.
\ "Madness is rare in individuals, but in groups, parties, |
`\ nations and ages it is the rule." -- Friedrich Nietzsche |
More information about the Python-list