[Tutor] renaming input works intermittently
Steven D'Aprano
steve at pearwood.info
Fri Jul 12 05:21:34 CEST 2013
On 12/07/13 11:07, eryksun wrote:
> On Thu, Jul 11, 2013 at 9:01 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>>> try:
>>> if int(sys.version[0]) < 3:
>>> input = raw_input
>>> numbers_str = original = input('Enter a positive'
>>> 'integer, space separated if desired.') # error occurs here
>>>
>>> Oddly, the error only occurs in Python 3.3 - the above works in Python 2.7
>>
>> The rules for local variables are rather more complicated in Python 2 and it
>> may be that you're somehow slipping through the cracks.
>
> In 2.x the if statement executes, so the local variable "input" gets assigned.
/facepalm
Ah, I mean, I knew that!
--
Steven
More information about the Tutor
mailing list