migrating to packages

Carl Banks pavlovevidence at gmail.com
Wed Oct 3 23:00:20 EDT 2007


On Wed, 03 Oct 2007 22:28:57 -0300, gherzig wrote:


>> On Oct 3, 2007, at 11:42 AM, Gerardo Herzig wrote:
>>
>>> Hi all. I have a single file with several classes, wich i want to
>>> separate into several packages.
>>> The big file is named, say MYCLASES, and contains a class named
>>> A(object), and B(A).
>>>
>>> We have been using this MYCLASES in the from MYCLASES import B syntax,
>>> but i cant reproduce this syntax using packages. Im forced to write
>>> from PACKAGE.B import *, and if that means
>>> i have to touch so many files, that would really be a problem to me.
>>> There is (i cant find it yet) a place where i can read about that kind
>>> of package 'migration' situation?
>>>
>>> Because i *really* want to keep the FROM PACKAGE import B syntax.
>>
>> http://www.python.org/doc/current/tut/
>> node8.html#SECTION008400000000000000000
> I have already read those files (and i just read it again), but still
> cant find the solution. Maybe i just do not explain myself in the
> correct way (or  i am very very stupid :)
> I will expose my case quicly.
> The MYCLASES.py file contains the A class, so i can use from MYCLASES
> import A
> a = ()
> 
> Using the "package mode" (wich looks fine BTW), having the simple
> MYCLASES/
>      __init__.py
>      A.py
> 
> forces my (i guess) to use the
> from MYCLASES.A import A
> 
> which is not what i want, because the big amount of files i will have to
> modify (and im not alones, there is a group of dudes who use this
> MYCLASES)
> 
> Im i missing something in that docs you post? Thanks!!

Add these lines in __init__.py:

from MYCLASSES.A import A
from MYCLASSES.B import B


Carl Banks




More information about the Python-list mailing list