Problems reading fra sys.stdin and later on duing raw_input

Alex alex at somewhere.round.here
Fri Mar 17 11:43:14 EST 2000


> I want to read a file from sys.stdin and then later on do a
> raw_input. But I get an error because sys.stdin is closed after the
> file is read.
> 
> Is there *any* way I can solve this problem?

Maybe you could use ncurses to read from the keyboard.  I've never used
it, but I'd be suprised if it goes through stdin.  I tried writing
something, but it segfaults for some reason:

#!/usr/bin/env python

import curses
from pdb import set_trace
st = set_trace

def get_line (prompt):
    screen = curses.initscr ()
    # screen.cbreak () # screen has neither of these attributes...
    # screen.noecho ()
    response = screen.getstr (0,0)
    screen.endwin ()
    return response

if __name__ == '__main__':
    import sys
    std_input = sys.stdin.readlines ()
    print 'This is what was piped:'
    # print std_input
    keyboard_input = get_line ('Enter something else: ')
    print 'This is what was typed:'
    print keyboard_input

This was based on the tutorial at http://python.org/doc/howto/curses/
    
Alex.



More information about the Python-list mailing list