migrating to packages
Bruno Desthuilliers
bruno.42.desthuilliers at wtf.websiteburo.oops.com
Thu Oct 4 04:26:31 EDT 2007
Hrvoje Niksic a écrit :
> gherzig at fmed.uba.ar writes:
>
>> 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
>
> Exactly. Using mypackage.mymodule instead of just mymodule is the
> entire *point* of a package.
Nope. The "entire point" of packages is to let you organize your code
and namespace. And it's quite common to use the __init__.py of the
package (as explained by Ben) as a facade to the internal organization
of the package, so you can change this internal organization without
breaking client code.
> That way, if someone creates another
> module with using the same name (mymodule), it won't conflict with
> yours. If you don't want to change mymodule to mypackage.mymodule,
> why use a package in the first place?
Because you have too much code to keep it in a single file.
More information about the Python-list
mailing list