PEP 312 - Making lambdas implicit worries me, surely it's just the name 'lambda' that is bad...

Alexander Schmolck a.schmolck at gmx.net
Thu Mar 6 15:26:16 EST 2003


Dave Brueck <dave at pythonapocrypha.com> writes:

> No, it is generally a no-no to do "from foo import *"

True, but I think there are exceptions (when qualified names or specifying
each import are quite awkward -- the only example that readily comes to mind
are math libraries or a library that is largely meant for interactive
use). Anyway, I just prefer not to litter -- it also makes it easier to get a
quick overview of the module by doing ``dir`` etc.

> >
> > Well, you asked for an example -- I vaguely remember that I did something like
> > this:
> >
> > ... [time + delta for time in computeTimes()] ...
> >
> > I then (possibly as an later addition) wanted to use the time module at a
> > later point in this function (which I had globally imported for other
> > functions). No big deal.
> 
> I guess it's a matter of coding style. To me it seems sloppy to be doing a
> a whole lot of module-level computation and/or using names of well-known

No argument that doing a lot of module-level compuation is sloppy, so I mainly
use one-liners on module level (computing a global variable or constant in a
single expression or (possibly looped) attribute asignments and other simple
reflection).


> modules as variables (e.g. using 'os' as a variable name _anywhere_ except
> the os module is bound to bite you eventually, regardless of whether or
> not listcomps "leak" into your namespace). If you don't have any qualms
> about using 'time' as a variable name, surely you've also been bitten by
> it when you used it in a for-loop, no?

I presume the reason I got bitten was my expectancy that list comp.s introduce
a new scope. I wouldn't have any qualms using time in ``map(lambda time,:
...`` or in a function signature since there is no good alternative word or
spelling.

> Nope, never. And it has _never_ caused me problems in practice.

Just out of curiosity, do you do much work in interactive shells?  Maybe our
stylistic differences might have to do with our working habbits -- much of the
code I write has to be 'import *' safe, because otherwise it would be
cumbersome for interactive sessions.

Anyway, I guess I'm just being overly pedantic, so I'll stop the nitpicking
now.


alex






More information about the Python-list mailing list