(std)input

Discussion in 'Python' started by Hegedus, Tamas ., Jun 25, 2004.

  1. Dear All,

    I am not a programmer, and I could not find out the solution of the following problem:
    I would like to pipe a program output to my python script; after it receives the EOF, I would like to get input from the users.
    I do not know the programmer expression of this process. Something like that: I would like to set the stdin back to the keyboard.

    A stupid example:
    --------------------------
    $cat text_file | my.py
    Reading text_file...
    text_file was loaded
    Enter your comment:
    --------------------------

    Thanks for your help,
    Tamas
    Hegedus, Tamas ., Jun 25, 2004
    #1
    1. Advertising

  2. Hegedus, Tamas .

    Larry Bates Guest

    You might think of this a different way.

    python my.py text_file
    Enter your comment:

    Have the python program pick up the file from
    the argument list and read its contents, then
    use raw_input to prompt the user.

    You can do this with something like:

    import sys
    try: input_file=sys.argv[1]
    except:
    print "No input file specified, aborting"
    sys.exit(2)

    fp=open(input_file, 'r')
    print "Reading text_file..."
    data=fp.read()
    fp.close()
    print "text_file was loaded"
    comment=raw_input("Enter your comment")

    HTH,
    Larry Bates
    Syscon, Inc.


    "Hegedus, Tamas ." <> wrote in message
    news:...
    > Dear All,
    >
    > I am not a programmer, and I could not find out the solution of the

    following problem:
    > I would like to pipe a program output to my python script; after it

    receives the EOF, I would like to get input from the users.
    > I do not know the programmer expression of this process. Something like

    that: I would like to set the stdin back to the keyboard.
    >
    > A stupid example:
    > --------------------------
    > $cat text_file | my.py
    > Reading text_file...
    > text_file was loaded
    > Enter your comment:
    > --------------------------
    >
    > Thanks for your help,
    > Tamas
    >
    Larry Bates, Jun 26, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page