Quick help for a python newby, please
Wildman
best_lay at yahoo.com
Thu Nov 24 00:46:07 EST 2016
On Thu, 24 Nov 2016 14:49:27 +1100, Chris Angelico wrote:
> On Thu, Nov 24, 2016 at 2:41 PM, Wildman via Python-list
> <python-list at python.org> wrote:
>> Point taken. I did miss the python3 part.
>>
>> I switched to raw_input because it handles an empty
>> input. An empty input would trigger the ValueError.
>> No doubt with the correct code the same or similar
>> could be done with input(). My lack of experience
>> caused me to look for simpler solution and perhaps
>> the wrong one.
>
> The exact same thing is true of input() in Python 3. In Python 2,
> input() is the same as eval(raw_input()), so don't use it ever [1].
> You can happily use input() in Py3, even if you get empty input.
>
> I like to put this at the top of cross-version scripts:
>
> try: input = raw_input
> except NameError: pass
>
> Then you can proceed to use input() without worries.
>
> ChrisA
>
> [1] Yes, I'm aware there are times when evalling the user's input is
> what you want. In those cases, be explicit and use eval.
Understood. Thank you.
--
<Wildman> GNU/Linux user #557453
The cow died so I don't need your bull!
More information about the Python-list
mailing list