Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44023
| References | <bd744d80-9abe-439e-a193-7db869d4a027@googlegroups.com> |
|---|---|
| Date | 2013-04-22 10:56 +1000 |
| Subject | Re: Weird behaviour? |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.892.1366592174.3114.python-list@python.org> (permalink) |
On Mon, Apr 22, 2013 at 10:37 AM, <jussij@zeusedit.com> wrote: > Can someone please explain the following behaviour? > > If I run the macro using the -u (flush buffers) option the if statement always fails: > > C:\Temp>python.exe -u c:\temp\test.py > Please Input 120: > 120 > Value Inputed: 120 > No Here's the essence of your program: print(repr(raw_input())) You can use that to verify what's going on. Try running that with and without the -u option; note, by the way, that -u actually means "unbuffered", not "flush buffers". You're running this under Windows. The convention on Windows is for end-of-line to be signalled with \r\n, but the convention inside Python is to use just \n. With the normal use of buffered and parsed input, this is all handled for you; with unbuffered input, that translation also seems to be disabled, so your string actually contains '120\r', as will be revealed by its repr(). By the way, raw_input() already returns a string. There's no need to str() it. :) ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Weird behaviour? jussij@zeusedit.com - 2013-04-21 17:37 -0700
Re: Weird behaviour? Chris Angelico <rosuav@gmail.com> - 2013-04-22 10:56 +1000
Re: Weird behaviour? jussij@zeusedit.com - 2013-04-21 18:11 -0700
Re: Weird behaviour? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-22 01:19 +0000
Re: Weird behaviour? nn <pruebauno@latinmail.com> - 2013-04-22 07:29 -0700
Re: Weird behaviour? jussij@zeusedit.com - 2013-04-22 16:06 -0700
Re: Weird behaviour? Chris Angelico <rosuav@gmail.com> - 2013-04-23 10:04 +1000
Re: Weird behaviour? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-23 00:31 +0000
Re: Weird behaviour? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-22 01:05 +0000
Re: Weird behaviour? jussij@zeusedit.com - 2013-04-21 18:14 -0700
Re: Weird behaviour? Chris Angelico <rosuav@gmail.com> - 2013-04-22 11:13 +1000
csiph-web