sys.stdin.read question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • It's me

    #1

    sys.stdin.read question

    Why do I get an "AttributeError : read" message when I do:

    import sys
    r=sys.stdin.rea d()

    ??

    I've tried:

    r=sys.stdin.rea d(80)
    r=sys.stdin.rea d(1)

    same error message.

    I couldn't find any reference to this function in my Python book (they have
    the stdout but not in).

    Some sample code I saw uses this function in the same manner I am and so I
    am assuming this is the correct syntax?

    Or is this a bug in Python 2.4?

    --
    It's me


  • Grant Edwards

    #2
    Re: sys.stdin.read question

    On 2004-12-07, It's me <itsme@yahoo.co m> wrote:[color=blue]
    > Why do I get an "AttributeError : read" message when I do:
    >
    > import sys
    > r=sys.stdin.rea d()[/color]

    Dunno. Works fine for me under 2.3.4, and according to the
    docs, should work under 2.4.

    What do you get when you do this:

    import sys
    type(sys.stdin)
    dir(sys.stdin)
    [color=blue]
    > Some sample code I saw uses this function in the same manner I
    > am and so I am assuming this is the correct syntax?[/color]

    Should be.
    [color=blue]
    > Or is this a bug in Python 2.4?[/color]

    That would be a little hard to believe.

    --
    Grant Edwards grante Yow! PEGGY FLEMMING is
    at stealing BASKET BALLS to
    visi.com feed the babies in VERMONT.

    Comment

    • Caleb Hattingh

      #3
      Re: sys.stdin.read question

      Hi

      You are probably typing this within IDLE. Try it after starting python in
      a shell like DOS or Bash. Should work then (works for me, and I also get
      the AttributeError in IDLE.

      Thanks
      Caleb

      On Tue, 07 Dec 2004 21:15:51 GMT, It's me <itsme@yahoo.co m> wrote:
      [color=blue]
      > Why do I get an "AttributeError : read" message when I do:
      >
      > import sys
      > r=sys.stdin.rea d()
      >
      > ??
      >
      > I've tried:
      >
      > r=sys.stdin.rea d(80)
      > r=sys.stdin.rea d(1)
      >
      > same error message.
      >
      > I couldn't find any reference to this function in my Python book (they
      > have
      > the stdout but not in).
      >
      > Some sample code I saw uses this function in the same manner I am and so
      > I
      > am assuming this is the correct syntax?
      >
      > Or is this a bug in Python 2.4?
      >
      > --
      > It's me
      >
      >[/color]

      Comment

      • Caleb Hattingh

        #4
        Re: sys.stdin.read question

        It runs properly in a shell (bash), but on another matter:

        '>>> r=sys.stdin.rea d(1)
        g
        '>>> r
        'g'
        '>>> r=sys.stdin.rea d(5)
        1234567890
        '>>> r
        '\n1234'
        '>>>

        What exactly happened to my 1234567890? I understand that I am only
        taking 5 characters, but where does the newline (\n) come from? Is that a
        remnant from when I terminated the previous 'g' input?

        Thanks
        Caleb


        On Tue, 07 Dec 2004 23:36:56 -0500, Caleb Hattingh <caleb1@telkoms a.net>
        wrote:
        [color=blue]
        > Hi
        >
        > You are probably typing this within IDLE. Try it after starting python
        > in a shell like DOS or Bash. Should work then (works for me, and I also
        > get the AttributeError in IDLE.
        >
        > Thanks
        > Caleb
        >
        > On Tue, 07 Dec 2004 21:15:51 GMT, It's me <itsme@yahoo.co m> wrote:
        >[color=green]
        >> Why do I get an "AttributeError : read" message when I do:
        >>
        >> import sys
        >> r=sys.stdin.rea d()
        >>
        >> ??
        >>
        >> I've tried:
        >>
        >> r=sys.stdin.rea d(80)
        >> r=sys.stdin.rea d(1)
        >>
        >> same error message.
        >>
        >> I couldn't find any reference to this function in my Python book (they
        >> have
        >> the stdout but not in).
        >>
        >> Some sample code I saw uses this function in the same manner I am and
        >> so I
        >> am assuming this is the correct syntax?
        >>
        >> Or is this a bug in Python 2.4?
        >>
        >> --
        >> It's me
        >>
        >>[/color]
        >[/color]

        Comment

        • It's me

          #5
          Re: sys.stdin.read question


          "Grant Edwards" <grante@visi.co m> wrote in message
          news:41b62008$0 $9746$a1866201@ visi.com...[color=blue]
          > On 2004-12-07, It's me <itsme@yahoo.co m> wrote:[color=green]
          > > Why do I get an "AttributeError : read" message when I do:
          > >
          > > import sys
          > > r=sys.stdin.rea d()[/color]
          >
          > Dunno. Works fine for me under 2.3.4, and according to the
          > docs, should work under 2.4.
          >
          > What do you get when you do this:
          >
          > import sys[/color]

          Done that.
          [color=blue]
          > type(sys.stdin)[/color]

          I get:

          <type 'instance'>
          [color=blue]
          > dir(sys.stdin)[/color]

          I get:

          ['_RPCProxy__att ributes', '_RPCProxy__get attributes',
          '_RPCProxy__get methods', '_RPCProxy__met hods', '__doc__', '__getattr__',
          '__init__', '__module__', 'encoding', 'oid', 'sockio']
          [color=blue]
          >[color=green]
          > > Some sample code I saw uses this function in the same manner I
          > > am and so I am assuming this is the correct syntax?[/color]
          >
          > Should be.
          >[color=green]
          > > Or is this a bug in Python 2.4?[/color]
          >
          > That would be a little hard to believe.
          >[/color]

          Well, here's a copy from the Python Shell output:
          [color=blue][color=green][color=darkred]
          >>> print sys.stdin.read( 5)[/color][/color][/color]

          Traceback (most recent call last):
          File "<pyshell#2 6>", line 1, in -toplevel-
          print sys.stdin.read( 5)
          AttributeError: read[color=blue][color=green][color=darkred]
          >>>[/color][/color][/color]

          ????????


          Comment

          • Grant Edwards

            #6
            Re: sys.stdin.read question

            On 2004-12-07, It's me <itsme@yahoo.co m> wrote:
            [color=blue][color=green]
            >> Dunno. Works fine for me under 2.3.4, and according to the
            >> docs, should work under 2.4.
            >>
            >> What do you get when you do this:
            >>
            >> import sys[/color]
            >
            > Done that.
            >[color=green]
            >> type(sys.stdin)[/color]
            >
            > I get:
            >
            > <type 'instance'>
            >[color=green]
            >> dir(sys.stdin)[/color]
            >
            > I get:
            >
            > ['_RPCProxy__att ributes', '_RPCProxy__get attributes',
            > '_RPCProxy__get methods', '_RPCProxy__met hods', '__doc__', '__getattr__',
            > '__init__', '__module__', 'encoding', 'oid', 'sockio'][/color]
            [color=blue]
            > ????????[/color]

            As somebody else already suggested, you must be running your
            program inside some sort of IDE that replaces sys.stdin with
            some other object that doesn't have a read() method. Try
            running the program from a shell prompt.


            --
            Grant Edwards grante Yow! Someone in DAYTON,
            at Ohio is selling USED
            visi.com CARPETS to a SERBO-CROATIAN

            Comment

            • Grant Edwards

              #7
              Re: sys.stdin.read question

              On 2004-12-08, Caleb Hattingh <caleb1@telkoms a.net> wrote:
              [color=blue]
              > It runs properly in a shell (bash), but on another matter:
              >
              > '>>> r=sys.stdin.rea d(1)
              > g
              > '>>> r
              > 'g'
              > '>>> r=sys.stdin.rea d(5)
              > 1234567890
              > '>>> r
              > '\n1234'
              > '>>>
              >
              > What exactly happened to my 1234567890? I understand that I am only
              > taking 5 characters, but where does the newline (\n) come from? Is that a
              > remnant from when I terminated the previous 'g' input?[/color]

              Exactly.

              The input stream consisted of 'g\n1234567890\ n'

              --
              Grant Edwards grante Yow! My EARS are GONE!!
              at
              visi.com

              Comment

              • Lars Tengnagel

                #8
                Re: sys.stdin.read question

                Hej Caleb and others

                I've been strugling with the same problem where i try to use popen3 to run a
                program. If I use a piped commandline
                the program can read the file without problems but in the IDLE and with
                popen it comes with an error.
                I haven't been able to read the stdin either so the problem so far is
                unsolved for my point.
                But the newline command would explain my problems with the program.
                Can it be a problem under windows since I'm using XP and the winpython

                Hopefully Lars

                "Caleb Hattingh" <caleb1@telkoms a.net> skrev i en meddelelse
                news:opsin95ryq 1js0xs@news.tel komsa.net...[color=blue]
                > It runs properly in a shell (bash), but on another matter:
                >
                > '>>> r=sys.stdin.rea d(1)
                > g
                > '>>> r
                > 'g'
                > '>>> r=sys.stdin.rea d(5)
                > 1234567890
                > '>>> r
                > '\n1234'
                > '>>>
                >
                > What exactly happened to my 1234567890? I understand that I am only
                > taking 5 characters, but where does the newline (\n) come from? Is that a
                > remnant from when I terminated the previous 'g' input?
                >
                > Thanks
                > Caleb
                >
                >
                > On Tue, 07 Dec 2004 23:36:56 -0500, Caleb Hattingh <caleb1@telkoms a.net>
                > wrote:
                >[color=green]
                >> Hi
                >>
                >> You are probably typing this within IDLE. Try it after starting python
                >> in a shell like DOS or Bash. Should work then (works for me, and I also
                >> get the AttributeError in IDLE.
                >>
                >> Thanks
                >> Caleb
                >>
                >> On Tue, 07 Dec 2004 21:15:51 GMT, It's me <itsme@yahoo.co m> wrote:
                >>[color=darkred]
                >>> Why do I get an "AttributeError : read" message when I do:
                >>>
                >>> import sys
                >>> r=sys.stdin.rea d()
                >>>
                >>> ??
                >>>
                >>> I've tried:
                >>>
                >>> r=sys.stdin.rea d(80)
                >>> r=sys.stdin.rea d(1)
                >>>
                >>> same error message.
                >>>
                >>> I couldn't find any reference to this function in my Python book (they
                >>> have
                >>> the stdout but not in).
                >>>
                >>> Some sample code I saw uses this function in the same manner I am and
                >>> so I
                >>> am assuming this is the correct syntax?
                >>>
                >>> Or is this a bug in Python 2.4?
                >>>
                >>> --
                >>> It's me
                >>>
                >>>[/color]
                >>[/color]
                >[/color]


                Comment

                • It's me

                  #9
                  Re: sys.stdin.read question

                  Yes, if I run the script from the command prompt, it works. I was running
                  it inside the Python IDE.

                  Thanks,

                  --
                  It's me


                  "Grant Edwards" <grante@visi.co m> wrote in message
                  news:41b628c9$0 $11072$a1866201 @visi.com...[color=blue]
                  > On 2004-12-07, It's me <itsme@yahoo.co m> wrote:
                  >[color=green][color=darkred]
                  > >> Dunno. Works fine for me under 2.3.4, and according to the
                  > >> docs, should work under 2.4.
                  > >>
                  > >> What do you get when you do this:
                  > >>
                  > >> import sys[/color]
                  > >
                  > > Done that.
                  > >[color=darkred]
                  > >> type(sys.stdin)[/color]
                  > >
                  > > I get:
                  > >
                  > > <type 'instance'>
                  > >[color=darkred]
                  > >> dir(sys.stdin)[/color]
                  > >
                  > > I get:
                  > >
                  > > ['_RPCProxy__att ributes', '_RPCProxy__get attributes',
                  > > '_RPCProxy__get methods', '_RPCProxy__met hods', '__doc__', '__getattr__',
                  > > '__init__', '__module__', 'encoding', 'oid', 'sockio'][/color]
                  >[color=green]
                  > > ????????[/color]
                  >
                  > As somebody else already suggested, you must be running your
                  > program inside some sort of IDE that replaces sys.stdin with
                  > some other object that doesn't have a read() method. Try
                  > running the program from a shell prompt.
                  >
                  >
                  > --
                  > Grant Edwards grante Yow! Someone in[/color]
                  DAYTON,[color=blue]
                  > at Ohio is selling USED
                  > visi.com CARPETS to a[/color]
                  SERBO-CROATIAN


                  Comment

                  • Caleb Hattingh

                    #10
                    Re: sys.stdin.read question

                    I don't have much experience with popen3. I do know that IDLE
                    (interactive interpreter) does something to sys.stdin, and that is
                    probably the problem you are seeing. Try your commands through the python
                    interactive interpreter started from a shell (DOS or Bash), see if it
                    still happens.

                    thx
                    Caleb


                    On Tue, 7 Dec 2004 23:16:50 +0100, Lars Tengnagel <lars@xvet.dk > wrote:
                    [color=blue]
                    > Hej Caleb and others
                    >
                    > I've been strugling with the same problem where i try to use popen3 to
                    > run a
                    > program. If I use a piped commandline
                    > the program can read the file without problems but in the IDLE and with
                    > popen it comes with an error.
                    > I haven't been able to read the stdin either so the problem so far is
                    > unsolved for my point.
                    > But the newline command would explain my problems with the program.
                    > Can it be a problem under windows since I'm using XP and the winpython
                    >
                    > Hopefully Lars
                    >
                    > "Caleb Hattingh" <caleb1@telkoms a.net> skrev i en meddelelse
                    > news:opsin95ryq 1js0xs@news.tel komsa.net...[color=green]
                    >> It runs properly in a shell (bash), but on another matter:
                    >>
                    >> '>>> r=sys.stdin.rea d(1)
                    >> g
                    >> '>>> r
                    >> 'g'
                    >> '>>> r=sys.stdin.rea d(5)
                    >> 1234567890
                    >> '>>> r
                    >> '\n1234'
                    >> '>>>
                    >>
                    >> What exactly happened to my 1234567890? I understand that I am only
                    >> taking 5 characters, but where does the newline (\n) come from? Is
                    >> that a
                    >> remnant from when I terminated the previous 'g' input?
                    >>
                    >> Thanks
                    >> Caleb
                    >>
                    >>
                    >> On Tue, 07 Dec 2004 23:36:56 -0500, Caleb Hattingh <caleb1@telkoms a.net>
                    >> wrote:
                    >>[color=darkred]
                    >>> Hi
                    >>>
                    >>> You are probably typing this within IDLE. Try it after starting python
                    >>> in a shell like DOS or Bash. Should work then (works for me, and I
                    >>> also
                    >>> get the AttributeError in IDLE.
                    >>>
                    >>> Thanks
                    >>> Caleb
                    >>>
                    >>> On Tue, 07 Dec 2004 21:15:51 GMT, It's me <itsme@yahoo.co m> wrote:
                    >>>
                    >>>> Why do I get an "AttributeError : read" message when I do:
                    >>>>
                    >>>> import sys
                    >>>> r=sys.stdin.rea d()
                    >>>>
                    >>>> ??
                    >>>>
                    >>>> I've tried:
                    >>>>
                    >>>> r=sys.stdin.rea d(80)
                    >>>> r=sys.stdin.rea d(1)
                    >>>>
                    >>>> same error message.
                    >>>>
                    >>>> I couldn't find any reference to this function in my Python book (they
                    >>>> have
                    >>>> the stdout but not in).
                    >>>>
                    >>>> Some sample code I saw uses this function in the same manner I am and
                    >>>> so I
                    >>>> am assuming this is the correct syntax?
                    >>>>
                    >>>> Or is this a bug in Python 2.4?
                    >>>>
                    >>>> --
                    >>>> It's me
                    >>>>
                    >>>>
                    >>>[/color]
                    >>[/color]
                    >
                    >[/color]

                    Comment

                    Working...