Accepting text input
Collin
collinyeung at shaw.ca
Tue May 13 21:02:36 EDT 2008
Gabriel Genellina wrote:
> En Mon, 12 May 2008 01:54:28 -0300, Collin <collinyeung at shaw.ca> escribió:
>
>> Collin wrote:
>>> I'm pretty new to Python, but this has really bugged me. I can't find a
>>> way around it.
>>>
>>>
>>> The problem is that, when I use raw_input("sajfasjdf") whatever, or
>>> input("dsjfadsjfa"), you can only have numerical values as answers.
>>>
>>> Any help would be appreciated. Thanks.
>>
>> Oh, wow. I feel so stupid. Please disregard this message. <_<
>
> No need to apologize...
>
>> I read the error message just now a bit more carefully, and I tried
>> something. I tried defining "yes" as some random numerical value. Then
>> when I did:
>> (example code)
>>
>> yes = 123123983 #some number
>> test = input("Test test test ")
>> if test == yes:
>> print "It worked."
>> else:
>> print "failed"
>>
>> (example code off)
>
> The usual way for Python<3.0 is:
>
> answer = raw_input("Test test test ").lower()
> if answer == "yes":
> ...
>
> The input() function evaluates user input as an expression: if he types 2+5 the input() function returns the integer 7. I would never use input() in a program - it's way too unsafe; use always raw_input instead.
>
If I use it like that, do I have to import anything to have the .lower()
work? And if I do, what does the .lower() signify?
More information about the Python-list
mailing list