Namespaces question

Aahz Maruch aahz at panix.com
Mon Mar 26 18:41:48 EST 2001


In article <mailman.985627029.26291.python-list at python.org>,
Chris Withers  <chrisw at nipltd.com> wrote:
>
>def create(self):
>
>    for name in ['x','y','z']:
>        value = session.get(name,None)
>        if value is None:
>            errors.append('No %s supplied.' % name)
>        else:
>            locals()[name]=value
>
>    if errors:
>        return errors
>
>    print x
>
>...now I know it's not right, 'cos I get a NameError on x at the print
>statement.
>
>What should I be using instead of locals()?

Just use a dictionary: "print dict['x']" works fine
-- 
                      --- Aahz  <*>  (Copyright 2001 by aahz at pobox.com)

Androgynous poly kinky vanilla queer het Pythonista   http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"Boost the stock market -- fire someone"



More information about the Python-list mailing list