[Tutor] need help with msvcrt.getch()

Richard D. Moores rdmoores at gmail.com
Tue Jul 27 17:57:12 CEST 2010


On Tue, Jul 27, 2010 at 07:51, Nick Raptis <airscorp at otenet.gr> wrote:

> On 07/27/2010 05:22 PM, Richard D. Moores wrote:
>
>> Python 3.1 on Vista.
>>
>> Please see <http://tutoree7.pastebin.com/f3TaxDBc>.
>>
>> I'm trying to recall what I used to know, thus this simple script. But 'y'
>> or 'q' do nothing. What's wrong?
>>
>> Thanks,
>>
>> Dick Moores
>>
>>
> Hi Dick!
> I'm not on Windows here so this might be a wild guess.
>
> From the documentation I gather that msvcrt can work either on binary or
> text mode.
> Perhaps you operate in the wrong one and need to switch with
> msvcrt.setmode(/)
>
> Anyway, insert some print lines to see what exactly is it that /getch()
> gets and debug from there
>

On <http://docs.python.org/py3k/library/msvcrt.html#module-msvcrt> I find
 msvcrt.setmode(*fd*,
*flags*)¶<http://docs.python.org/py3k/library/msvcrt.html#msvcrt.setmode>
Set
the line-end translation mode for the file descriptor *fd*. To set it to
text mode, *flags* should be
os.O_TEXT<http://docs.python.org/py3k/library/os.html#os.O_TEXT>;
for binary, it should be
os.O_BINARY<http://docs.python.org/py3k/library/os.html#os.O_BINARY>
.But I don't understand how to implement this. I've tried <
http://tutoree7.pastebin.com/gYbq67Ja>, but get

C:\P31Working>test_getch1b.py
Traceback (most recent call last):
  File "C:\P31Working\test_getch1b.py", line 7, in <module>
    msvcrt.setmode(1,os._TEXT)
AttributeError: 'module' object has no attribute '_TEXT'

Nick, could you spell out for me what you are suggesting? I like the
possibility of not having to use b'y' instead of 'y'.

Dick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100727/2639d1e3/attachment.html>


More information about the Tutor mailing list