[Tutor] variable from input?

Glen Wheeler gew75 at hotmail.com
Tue Oct 26 02:48:28 CEST 2004


  Howdy.

  Firstly, I cannot think of any reason why you would want to do this 
instead of simply having a ``name'' variable holding that person's name.

  Anyway, the following would work:

>>> s = raw_input("Don't try this at home...")
>>> exec(s+" = ''")
>>> fred
''
>>>

  But don't do it...

  Glen

----- Original Message ----- 
From: "Liam Clarke" <cyresse at gmail.com>
To: "Python Tutor" <tutor at python.org>
Sent: Tuesday, October 26, 2004 10:12 AM
Subject: Re: [Tutor] variable from input?


> That's an interesting one...
>
> You could have the variable contained in a separate module, and then
> when the user enters the variable name, have another function write
> that variable name throughout the other module, and then reimport the
> other module, but that would only work if the variable were entirely
> contained within that module.
>
> But I've wondered that myself, but the implementation doesn't seem to
> be worth the effort.
> Once again, I could be entirely wrong.
>
> Liam
>
>
> On Mon, 25 Oct 2004 19:53:22 -0400, Rene Lopez <renx99 at gmail.com> wrote:
>> is it possible to have the user input something with a raw_input
>> command, and then base upon the input make that into the name of a
>> variable?
>>
>> for example:
>>
>> answer = raw_input("what is your name?")
>>
>> user types in Rene, and some how we end up with a variable named Rene?
>> --
>>
>> Rene
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
>
> -- 
> 'There is only one basic human right, and that is to do as you damn well 
> please.
> And with it comes the only basic human duty, to take the consequences.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


More information about the Tutor mailing list