Applications/examples of some advanced Py features, please !

Andrew Dalke adalke at mindspring.com
Sat Jan 4 14:46:37 EST 2003


Az Tech wrote:
> 1. lambda
> (I understand the basic usage - simple examples - but I'm not able to
> 'wrap my head around' how to use it a way that will be of benefit.
> Pls. see below for more on this.
> 
> 2. nested functions - a little info was given by Danny in reply to my
> earlier post on local-static variables, but I would like more.
> 
> 3. Thoughts on implementing Interfaces in Py - a la Java interfaces.
   ...
 > I suspect that some of the above 3 points will help me to write my
 > app in a better way. though not sure, of course. Hence the request
 > for examples.

As someone who has used Python for >5 years, let me assure you that
you don't need to focus on these features to write your software.

1. Don't use lambda.

It's good for a few things, but in many cases you should use a
list comprehension.  For an example, cgi.py has

      plist = map(lambda x: x.strip(), line.split(';'))

as a list comprehension this is more more clearly written as

      plist = [x.strip() for x in line.split(';')]

2. nested functions

Again, it's very unlikely you'll need nested functions.  Eg, look
in the standard library and you'll find few uses of them.  There
are a few cases when they are useful, but they are tricky.

3. Interfaces

You don't need them.


Based in your post, it's best for you to work on object design,
coding, etc. and not be as concerned with these relatively
esoteric features of Python.

					Andrew
					dalke at dalkescientific.com





More information about the Python-list mailing list