[Tutor] Comma at the end of a print command
Dragonfirebane at aol.com
Dragonfirebane at aol.com
Sun Aug 15 16:49:30 CEST 2004
In a message dated 8/15/2004 5:23:29 AM Eastern Standard Time,
alan.gauld at blueyonder.co.uk writes:
> I know that when you put a comma at the end of a print command, the
next
> printed object will be printed on the same line, separated by a
space. Is there a
> way to do this without the space separation? i.e.:
I dont think so but you can write to sys.stdout instead and
do all the formatting yourself.
I'll try that, thanks.
> def mod():
> import msvcrt
> model = msvcrt.getch()
> if model == '1':
> print model(*)
> model = msvcrt.getch() ##to get the next number
> print model
This is most likely to bring back another 1 or a null character
because the time between detecting the 1 and reading getch again
is going to be tiny. You will need to loop to detect the user input.
Using getch() is much more complex than using raw_input.
I've found that using msvcrt.getch() again merely forces the program to wait
until the next button pushed and processing it.
> 'real-time' printing without the space separation? The reason I'm
using
> msvcrt.getch() is because if the number doesn't begin with a 1, then
it must be below
> 10, as the choices are from 2 to 15; which would make it easier (no
need to hit
> enter) to process the choice.
This might seem like a good idea but it does put the onus on your
users to be perfect keyboard operators. That is they can never make
a mistake because as soon as they hit a key you will process it!
Just a consideration...
Alan G.
Well, since all the choices are numbers, they can use the number pad on the
right of the keyboard. Besides, its meant for a game in which each number
represents a tile that can slide into an empty space, as in the classic hand-held
game. Therefore, if they make a mistake, a) the tile is likely not to be next
to the space, which would do nothing but bring up a message requesting they
choose a tile next to the space or b) the tile *is* next to the space and if it
is not the one they wished to move, they merely select it again to move it
back. If you're interested, my code so far is at
http://rafb.net/paste/results/D4a3NE47.nln.html. As of right now, the timer seems to work arbitrarily (i don't
know why) as does the part that ends the program by breaking the play loop
when the user inputs 'stop', 'quit', 'exit', etc. Any suggestions on what's wrong
and how to fix it would be apreciated.
Thanks,
Orri
Email: dragonfirebane at aol.com
AIM: singingxduck
Programming Python for the fun of it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040815/2d11c95b/attachment.html
More information about the Tutor
mailing list