In article <[EMAIL PROTECTED]>,
 Benji York <[EMAIL PROTECTED]> wrote:

> Peter Maas wrote:
> >  >>> suffix = 'var'
> >  >>> vars()['a%s' % suffix] = 45
> >  >>> avar
> > 45
> 
> Quoting from http://docs.python.org/lib/built-in-funcs.html#l2h-76 about 
> the "vars" built in:
> 
> The returned dictionary should not be modified: the effects on the 
> corresponding symbol table are undefined.

If you really want to make something like this work you can define a 
class that would work like this:

vars = funkyclass()
varname = 'x'
vars[varname] = value
vars.x

But this is clearly a design mistake.  Either you know the names of the 
variables when you write the code or you do not.  If you know them you 
can simply assign them directly.  If you do not know them then you can't 
put them in the code to read their values anyway, and what you need is 
just a regular dictionary.

rg
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to