reading one byte from stdin

Discussion in 'Python' started by Mark McDuff, Jul 16, 2008.

  1. Mark McDuff

    Mark McDuff Guest

    I'm trying to read one byte from stdin, without the newline.

    If I try something like:
    I can input a character, but then I have to press enter, which leaves
    a newline character in the stdin buffer and requires two keypresses.
    Is there any way to read only one keypress in a simple manner (i.e. no
    curses)?
     
    Mark McDuff, Jul 16, 2008
    #1
    1. Advertisements

  2. Depending on your OS, yes. Under *nix, you need to set the terminal to
    RAW-mode.

    This recipe claims to be OS-agnostinc:

    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/134892

    Diez
     
    Diez B. Roggisch, Jul 16, 2008
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.