[CentralOH] Namespaces

Austin Godber godber at gmail.com
Tue Oct 19 23:51:23 CEST 2010


I tend to agree with Nick though I like the explicitness of #1.  I
have just been reading some old code today and I wish it had all been
done like #1, it would have helped my brain quickly understand exactly
what was going on without jumping around.

Actually, I think I would avoid #4 too, just to save myself the mental
substitution of the real package.module.  It may save you a bit of
effort when you write it, but if you ever have to go back and read it
again, #1 will make understanding it easier.

Austin

On Tue, Oct 19, 2010 at 4:51 PM, Nick Albright <nick.albright at gmail.com> wrote:
> Hola!
> Yeah, I avoid #3 (import *) all together.  Can easily lead to clashes/things
> you don't want happening, happening. :)
> I tend to use #2 and #4 depending on the case.  If I'm only using 1 function
> from that module, I'll just import that.  If I'm going to be using a series
> of functions, then I'll give it a quickly typed name, and use that.  And #1
> is just a long hand version of #4, and I like shorthand. = )
> Those be what little thoughts I have!
>  -Nick
>
> On Tue, Oct 19, 2010 at 4:33 PM, Mark Erbaugh <mark at microenh.com> wrote:
>>
>> Assume I have a objecy named obj in a module, module.py, in a package
>> named package.
>>
>> As I understand there are essentially three ways to access obj in a client
>> module:
>>
>> import package.module
>>
>> then everywhere func is used, it must be called using package.module.obj
>>
>> or
>>
>> from package.module import obj
>>
>> then everywhere obj is used, it can be called using just obj.
>>
>> or
>>
>> from package.module import *
>>
>> again everywhere obj is used, it can be called using just obj, but I have
>> read the cautions about using wild imports, so I'm discounting this option.
>>
>> or
>>
>> import package.module as pm
>>
>> then everywhere obj is used, it can be called using pm.obj
>>
>>
>>
>> What are the pros and cons and recommended best practices?
>>
>>
>> Thanks,
>> Mark
>>
>> _______________________________________________
>> CentralOH mailing list
>> CentralOH at python.org
>> http://mail.python.org/mailman/listinfo/centraloh
>
>
>
> --
> Please note that as of 1/20 I no longer have a land phone line, only my
> cell.
>
> _______________________________________________
> CentralOH mailing list
> CentralOH at python.org
> http://mail.python.org/mailman/listinfo/centraloh
>
>


More information about the CentralOH mailing list