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
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
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
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
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.
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
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