[CentralOH] Namespaces

Nick Albright nick.albright at gmail.com
Tue Oct 19 22:51:49 CEST 2010


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/mailman/private/centraloh/attachments/20101019/21f2bbf0/attachment.html>


More information about the CentralOH mailing list