can i make not wait?

Michael Hudson mwh21 at
Thu Dec 7 11:02:54 CET 2000

thelocust at writes:

> I'm working on a program that requires me to read in input (usually one
> character) if it is input.  For example, i have a while loop that looks
> like this:
> while 1:
>       x =
>       if x == 'q':
>            break
>       test.handlestuff()
> Well, my problem is is that it seems that read MUST have input to move
> on.  Is there any way that it just attempts to get whatever is on the
> TTY?  or maybe the last thing that was put to it?

You can use a mixture of, termios.tcsetattr and
to do what you want; something like this:

import termios
import TERMIOS
import os
import select,sys

def read1():
    oldattr = termios.tcgetattr(0)
        attr = termios.tcgetattr(0)
        attr[2] = (attr[2] & ~(TERMIOS.NLDLY)) | TERMIOS.NL0
        attr[3] = attr[3] & ~(TERMIOS.ICANON|TERMIOS.ECHO)
        while 1:
            r,_,_ =[0],[],[],0)
            if r:
                return ''

season-to-taste-ly y'rs

  please realize that the Common  Lisp community is more than 40 
  years old.  collectively, the community has already been where 
  every clueless newbie  will be going for the next three years.  
  so relax, please.                     -- Erik Naggum, comp.lang.lisp

More information about the Python-list mailing list