generator expression works in shell, NameError in script

greg greg at cosc.canterbury.ac.nz
Fri Jun 19 06:20:55 CEST 2009


ssc wrote:

> class SignupForm(Form):
> 
>     titles = ['Dr', 'Miss', 'Mr', 'Mrs', 'Ms',]
>     title_choices   = [(0, '')] + list((titles.index(t)+1, t) for t in
> titles)
> 
> Does the generator expression have its own little namespace or so ?

Yes. The generator expression is a function, with its
own local namespace. Since the class scope is not visible
from inside functions declared within it, the behaviour
you're seeing results.

-- 
Greg



More information about the Python-list mailing list