On Thu, May 10, 2007 at 07:45:13AM -0700, Spider 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.

A lot of code uses that paradigm. And it's neither clear nor pythonic.
Some people's code already seperated pylons functions, SQLAlchemy
functions etc.

> 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).

The "paster shell" helps you determine where a certain function comes
from.

> I think I'd find Pylons code easier to read if objects were coded as
> X.<name> rather than just plain <name>.

I second that. I wouldn't want to name all the functions explicitly
though because some are nested deeply and the code becomes very verbose.
But to avoid cluttering the namespace I sometimes use shortcuts like:

    import sqlalchemy.orm as orm

Or

    import sqlalchemy as sa

This means that other people still need to understand what weird name
you invented to abbreviate an imported class. So it's not perfect
either. But the "h" and "c" globals are already very dark magic. I'm
willing to accept those short names because everybody needs them time
and again. But since Pylons uses a dozen components it's very unwise to
import them all into one namespace. It's probably not easy to fix
because then the next project upgrade would mean changing a lot of code.

However I find your point very valid.

 Christoph


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to