py32 on windows - input() includes trailing \r
Frank Millman
frank at chagford.com
Wed Apr 20 09:14:35 EDT 2011
"Peter Otten" <__peter__ at web.de> wrote in message
news:iomla6$p8f$1 at dough.gmane.org...
> Frank Millman wrote:
>
>> On linux, python 3.2 -
>>
>>>>> x = input()
>> xyz
>>>>> len(x)
>> 3
>>>>> x
>> 'xyz'
>>
>> on windows, python 3.2 -
>>
>>>>> x = input()
>> xyz
>>>>> len(x)
>> 4
>>>>> x
>> 'xyz\r'
>>
>> Is this expected behaviour?
>
> No, that's a bug:
>
> http://bugs.python.org/issue11272
>
> IMO it's severe enough to warrant a brown-bag release...
>
Thanks, Peter.
I guess I should have checked the bug tracker first.
FWIW, I have found a workaround that seems to work on both platforms -
>>> x = input().rstrip()
xyz
>>> len(x)
3
>>> x
'xyz'
Obviously this will also strip trailing spaces, but it will do for my
purposes.
Frank
More information about the Python-list
mailing list