Re: [Tutor] Assigning variables with names set by other variables

2011-11-04 Thread Max gmail
Thank you, Wayne! This helps a lot. On Nov 4, 2011, at 5:38 PM, Wayne Werner wrote: > On Fri, Nov 4, 2011 at 4:21 PM, Max S. wrote: > Is it possible to create a variable with a string held by another variable in > Python? For example, > > >>> var_name = input("Variable name: ") > (input: 'var

Re: [Tutor] Assigning variables with names set by other variables

2011-11-04 Thread Max gmail
Thanks Steven. On Nov 4, 2011, at 6:45 PM, Steven D'Aprano wrote: > Max S. wrote: >> Is it possible to create a variable with a string held by another variable >> in Python? For example, > > Yes, but you shouldn't do it. Seriously. Don't do this, you will regret it. > >var_name = input("Var

Re: [Tutor] Assigning variables with names set by other variables

2011-11-04 Thread Steven D'Aprano
Max S. wrote: Is it possible to create a variable with a string held by another variable in Python? For example, Yes, but you shouldn't do it. Seriously. Don't do this, you will regret it. var_name = input("Variable name? ") # use raw_input in Python 2 exec("%s = 4" % var_name) Ins

Re: [Tutor] Assigning variables with names set by other variables

2011-11-04 Thread Terry Carroll
On Fri, 4 Nov 2011, Max S. wrote: Is it possible to create a variable with a string held by another variable in Python?  For example, It's possible, but in almost all cases where this comes up, the better approach is to use a dictionary.___ Tutor ma

Re: [Tutor] Assigning variables with names set by other variables

2011-11-04 Thread Peter Otten
Max S. wrote: > Is it possible to create a variable with a string held by another variable > in Python? For example, > var_name = input("Variable name: ") > (input: 'var') var_name = 4 print(var) > (output: 4) > > (Yeah, I know that if this gets typed into Python, it won't work.

Re: [Tutor] Assigning variables with names set by other variables

2011-11-04 Thread Wayne Werner
On Fri, Nov 4, 2011 at 4:21 PM, Max S. wrote: > Is it possible to create a variable with a string held by another variable > in Python? For example, > > >>> var_name = input("Variable name: ") > (input: 'var') > >>> var_name = 4 > >>> print(var) > (output: 4) > > (Yeah, I know that if this gets

[Tutor] Assigning variables with names set by other variables

2011-11-04 Thread Max S.
Is it possible to create a variable with a string held by another variable in Python? For example, >>> var_name = input("Variable name: ") (input: 'var') >>> var_name = 4 >>> print(var) (output: 4) (Yeah, I know that if this gets typed into Python, it won't work. It just pseudocode.) I'm on a