On 5/10/07, Spider <[EMAIL PROTECTED]> wrote:
> Python guru Fredrik Lundh has an article at
> http://effbot.org/zone/import-confusion.htm
> in which he discusses use of the import statement. He says,
> essentially :
> "import X" should be the normal method of importing
> "from X import *" is bad practice
> "from X import Y" is sometime ok
> That seems to be the general agreement in the python world.
>
> Some of the sample pylons applications and documentation use the "from
> X import *" format. Maybe we should consider changing that over time.
>
> For me as a newbie to Pylons, one of the drawbacks to the "from X
> import *" method is that imported objects end up in the global
> namespace, which makes it difficult to work out where a object comes
> from (made more complex since Pylons is a "glue" framework). I think
> I'd find Pylons code easier to read if objects were coded as X.<name>
> rather than just plain <name>.
>
> Anyhow, that's just a thought. I'd be interested in people's reaction
> to my obervations. In the meantime, I'll continue to enjoy playing
> around with Pylons.
Using "from module import *" with any old module is bad practice.
However, some modules are designed to be used with "from module import
*". In such cases, using "from module import *" is okay. Have a look
at what the Python style guide, PEP 8, says:
http://www.python.org/dev/peps/pep-0008/
In Pylons, the statement is "from mypackage.lib.base import *". If
you look at that module, you'll see a short list of things meant for
import by the "import *". You can add to this list. The important
thing is that the list is managed and under your control. It's there
for convenience because this is the type of stuff you're usually going
to need. If it weren't under your own control, I'd be against it too,
but I think this qualifies as an acceptable use for the sake of
convenience. If it irritates you, though, don't use it ;)
Best Regards,
-jj
--
http://jjinux.blogspot.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---