Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: Python User Input EOF Error Explained

  1. #11
    Join Date
    Jun 2009
    Beans
    8

    Re: Python User Input EOF Error Explained

    Like from a temp file? The current reason is that the script takes in raw input (a text version of a pdf report) processes it and converts results to a csv all in one module. The part with the user input comes right at the end before output to screen.

    Are you saying write the list to a temp file and then read it back in to ask the "triple duplicate" question to get around the "already used" stdin problem here?

  2. #12
    Join Date
    Nov 2005
    Location
    Sendai, Japan
    Beans
    11,296
    Distro
    Kubuntu

    Re: Python User Input EOF Error Explained

    Right now your script reads the file from stdin. Instead, you could make it read the file directly from the disk, then you get the data and parse it in exactly the same way you do it when reading from stdin, except that you read from the disk instead.
    「明後日の夕方には帰ってるからね。」


  3. #13
    Join Date
    May 2006
    Beans
    1,790

    Re: Python User Input EOF Error Explained

    You can read from the tty instead of from stdin, like this:

    Code:
    f=open("/dev/tty","r+")
    f.write("string")
    f.readline()
    There may be better ways to do it.

  4. #14
    Join Date
    Nov 2005
    Location
    Nashville, TN
    Beans
    437
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Python User Input EOF Error Explained

    It would help to know why you chose to pipe data into the script rather than having the script get the data. Are you going to pipe the output of other programs into it, or is that just the way you knew how to pass data to a script?

    If it's not something you intend to regularly pipe into then you'd be better off passing the file name as an argument like this.

    Code:
    import sys
    
    def get_file( file_name ):
        f = open( file_name, "r")
        file_buffer = f.read()
        f.close()
        return file_buffer
    
    def your_function( buffer ):
        # your code goes here
    
    def main():
        file_name = sys.argv[1]
        buffer = get_file( file_name )
        your_function( buffer )
    
    main()


    That way you can do this.

    Code:
    > myscript.py <filename>
    Last edited by Chayak; July 26th, 2011 at 07:01 PM.
    -Chayak

  5. #15
    Join Date
    Sep 2009
    Location
    Canada, Montreal QC
    Beans
    1,809
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Python User Input EOF Error Explained

    You can read from sys.stdin instead. It will act as raw_input in this case and will allow you to manipulate the input as a file.
    I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones.
    Freedom is measured in Stallmans.
    Projects: gEcrit

Page 2 of 2 FirstFirst 12

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •