sys.stdout

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sébastien Boisgérault

    sys.stdout

    Hi,

    The sys.stdout stream behaves strangely in my
    Python2.4 shell:
    [color=blue][color=green][color=darkred]
    >>> import sys
    >>> sys.stdout.writ e("AAAA")
    >>> sys.stdout.writ e("BBBB\n")[/color][/color][/color]
    BBBB[color=blue][color=green][color=darkred]
    >>> sys.stdout.writ e("CCCC\nDDDD ")[/color][/color][/color]
    CCCC[color=blue][color=green][color=darkred]
    >>> sys.stdout.flus h()[/color][/color][/color]
    [...nothing...]

    Have you ever seen sys.stdout behave like that ?
    Any idea what is wrong with my Python2.4 install
    or Linux (Mandrake 10.0) system ?

    Cheers,

    Sébastien

  • tiissa

    #2
    Re: sys.stdout

    Sébastien Boisgérault a écrit :[color=blue]
    > The sys.stdout stream behaves strangely in my
    > Python2.4 shell:
    >[color=green][color=darkred]
    > >>> import sys
    > >>> sys.stdout.writ e("AAAA")
    > >>> sys.stdout.writ e("BBBB\n")[/color][/color]
    > BBBB[color=green][color=darkred]
    > >>> sys.stdout.writ e("CCCC\nDDDD ")[/color][/color]
    > CCCC[color=green][color=darkred]
    > >>> sys.stdout.flus h()[/color][/color]
    > [...nothing...][/color]

    There are two things competing on your stdout: what you explicitely ask
    the program to write and the prompt and echo of the interpreter.

    Try this:

    import sys, time
    sys.stdout.writ e('aaa'); sys.stdout.flus h(); time.sleep(2)

    Comment

    • Sébastien Boisgérault

      #3
      Re: sys.stdout

      Tiissa,

      Thanks for your answer. The execution of your example leads to a
      'aaa' display during 2 secs, before it is erased by the prompt.

      This behavior is standard ? The standard output is not supposed
      to *concatenate* the 'aaa' and the '>>>' ?

      SB

      Comment

      • Robert Kern

        #4
        Re: sys.stdout

        Sébastien Boisgérault wrote:[color=blue]
        > Tiissa,
        >
        > Thanks for your answer. The execution of your example leads to a
        > 'aaa' display during 2 secs, before it is erased by the prompt.
        >
        > This behavior is standard ? The standard output is not supposed
        > to *concatenate* the 'aaa' and the '>>>' ?[/color]

        FWIW:

        Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
        [GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
        Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
        >>> import sys
        >>> sys.stdout.writ e('AAAA')[/color][/color][/color]
        AAAA>>> sys.stdout.writ e('BBBB\n')
        BBBB[color=blue][color=green][color=darkred]
        >>>[/color][/color][/color]

        --
        Robert Kern
        rkern@ucsd.edu

        "In the fields of hell where the grass grows high
        Are the graves of dreams allowed to die."
        -- Richard Harter

        Comment

        • Fredrik Lundh

          #5
          Re: sys.stdout

          Sébastien Boisgérault wrote:
          [color=blue]
          > Thanks for your answer. The execution of your example leads to a
          > 'aaa' display during 2 secs, before it is erased by the prompt.
          >
          > This behavior is standard ? The standard output is not supposed
          > to *concatenate* the 'aaa' and the '>>>' ?[/color]

          what "python shell" are you using, and what platform are you running
          it on? here's what I get on a standard Unix console:
          [color=blue][color=green][color=darkred]
          >>> import sys
          >>> sys.stdout.writ e("AAAA")[/color][/color][/color]
          AAAA>>> sys.stdout.writ e("BBBB\n")
          BBBB[color=blue][color=green][color=darkred]
          >>> sys.stdout.writ e("CCCC\nDDDD ")[/color][/color][/color]
          CCCC
          DDDD>>>

          </F>



          Comment

          • Sébastien Boisgérault

            #6
            Re: sys.stdout


            Robert Kern wrote:[color=blue]
            > Sébastien Boisgérault wrote:[color=green]
            > > Tiissa,
            > >
            > > Thanks for your answer. The execution of your example leads to a
            > > 'aaa' display during 2 secs, before it is erased by the prompt.
            > >
            > > This behavior is standard ? The standard output is not supposed
            > > to *concatenate* the 'aaa' and the '>>>' ?[/color]
            >
            > FWIW:
            >
            > Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
            > [GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
            > Type "help", "copyright" , "credits" or "license" for more information.[color=green][color=darkred]
            > >>> import sys
            > >>> sys.stdout.writ e('AAAA')[/color][/color]
            > AAAA>>> sys.stdout.writ e('BBBB\n')
            > BBBB[color=green][color=darkred]
            > >>>[/color][/color]
            >
            > --
            > Robert Kern
            > rkern@ucsd.edu[/color]

            Robert,

            I used to have exactly this behavior on my previous platform ...
            In the good old days ;)

            Do you know if this behavior is mandatory ? Can I *officially*
            <wink> state that my Python interpreter is broken ?

            I have already tried to recompile and reinstall Python2.4
            without any noticeable difference and the Python2.3 rpm
            that I have tested exhibits the same behavior ... Doh !


            SB

            Comment

            • Fredrik Lundh

              #7
              Re: sys.stdout

              > what "python shell" are you using, and what platform are you running[color=blue]
              > it on? here's what I get on a standard Unix console:
              >[color=green][color=darkred]
              >>>> import sys
              >>>> sys.stdout.writ e("AAAA")[/color][/color]
              > AAAA>>> sys.stdout.writ e("BBBB\n")
              > BBBB[color=green][color=darkred]
              >>>> sys.stdout.writ e("CCCC\nDDDD ")[/color][/color]
              > CCCC
              > DDDD>>>[/color]

              btw, what does
              [color=blue][color=green][color=darkred]
              >>> sys.stdout.enco ding[/color][/color][/color]

              print ?

              </F>



              Comment

              • Sébastien Boisgérault

                #8
                Re: sys.stdout


                Fredrik Lundh wrote:[color=blue]
                > Sébastien Boisgérault wrote:
                >[color=green]
                > > Thanks for your answer. The execution of your example leads to a
                > > 'aaa' display during 2 secs, before it is erased by the prompt.
                > >
                > > This behavior is standard ? The standard output is not supposed
                > > to *concatenate* the 'aaa' and the '>>>' ?[/color]
                >
                > what "python shell" are you using, and what platform are you running
                > it on?[/color]

                The python interpreter is invoked from a bash/konsole session,
                inside a KDE env.:

                bash$ python
                Python 2.4.1 (#4, Sep 8 2005, 19:11:54)
                [GCC 3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)] on linux2
                Type "help", "copyright" , "credits" or "license" for more
                information.[color=blue][color=green][color=darkred]
                >>>[/color][/color][/color]
                [color=blue]
                > here's what I get on a standard Unix console:
                >[color=green][color=darkred]
                > >>> import sys
                > >>> sys.stdout.writ e("AAAA")[/color][/color]
                > AAAA>>> sys.stdout.writ e("BBBB\n")
                > BBBB[color=green][color=darkred]
                > >>> sys.stdout.writ e("CCCC\nDDDD ")[/color][/color]
                > CCCC
                > DDDD>>>
                >
                > </F>[/color]

                Yep. And I hate you for this ;)

                Cheers,

                SB

                Comment

                • Sébastien Boisgérault

                  #9
                  Re: sys.stdout


                  Fredrik Lundh a écrit :
                  [color=blue][color=green]
                  > > what "python shell" are you using, and what platform are you running
                  > > it on? here's what I get on a standard Unix console:
                  > >[color=darkred]
                  > >>>> import sys
                  > >>>> sys.stdout.writ e("AAAA")[/color]
                  > > AAAA>>> sys.stdout.writ e("BBBB\n")
                  > > BBBB[color=darkred]
                  > >>>> sys.stdout.writ e("CCCC\nDDDD ")[/color]
                  > > CCCC
                  > > DDDD>>>[/color]
                  >
                  > btw, what does
                  >[color=green][color=darkred]
                  > >>> sys.stdout.enco ding[/color][/color]
                  >
                  > print ?
                  >
                  > </F>[/color]

                  [color=blue][color=green][color=darkred]
                  >>> sys.stdout.enco ding[/color][/color][/color]
                  'ISO-8859-15'


                  SB

                  Comment

                  • Jorgen Grahn

                    #10
                    Re: sys.stdout

                    On 9 Sep 2005 03:40:58 -0700, Sébastien Boisgérault <Sebastien.Bois gerault@gmail.c om> wrote:[color=blue]
                    >
                    > Fredrik Lundh wrote:[color=green]
                    >> Sébastien Boisgérault wrote:
                    >>[color=darkred]
                    >> > Thanks for your answer. The execution of your example leads to a
                    >> > 'aaa' display during 2 secs, before it is erased by the prompt.
                    >> >
                    >> > This behavior is standard ? The standard output is not supposed
                    >> > to *concatenate* the 'aaa' and the '>>>' ?[/color]
                    >>
                    >> what "python shell" are you using, and what platform are you running
                    >> it on?[/color]
                    >
                    > The python interpreter is invoked from a bash/konsole session,
                    > inside a KDE env.:[/color]

                    So, it's either of these things:
                    - konsole and its bugs/features
                    - your $TERM settings
                    - your readline and its bugs/features
                    - your ~/.inputrc settings (see the readline man page)

                    It's hard to say what's right and wrong really, and whose fault it is.
                    I'm pretty sure it's not Python. What happens if you try bash?

                    tuva:~> bash
                    grahn@tuva:~$ echo -n 'foo'
                    foograhn@tuva:~ $

                    /Jorgen

                    --
                    // Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
                    \X/ algonet.se> R'lyeh wgah'nagl fhtagn!

                    Comment

                    • Sébastien Boisgérault

                      #11
                      Re: sys.stdout


                      Jorgen Grahn a écrit :
                      [color=blue]
                      > On 9 Sep 2005 03:40:58 -0700, Sébastien Boisgérault <Sebastien.Bois gerault@gmail.c om> wrote:[color=green]
                      > >
                      > > Fredrik Lundh wrote:[color=darkred]
                      > >> Sébastien Boisgérault wrote:
                      > >>
                      > >> > Thanks for your answer. The execution of your example leads to a
                      > >> > 'aaa' display during 2 secs, before it is erased by the prompt.
                      > >> >
                      > >> > This behavior is standard ? The standard output is not supposed
                      > >> > to *concatenate* the 'aaa' and the '>>>' ?
                      > >>
                      > >> what "python shell" are you using, and what platform are you running
                      > >> it on?[/color]
                      > >
                      > > The python interpreter is invoked from a bash/konsole session,
                      > > inside a KDE env.:[/color]
                      >
                      > So, it's either of these things:
                      > - konsole and its bugs/features[/color]

                      Nothing that I could do about it ;)
                      [color=blue]
                      > - your $TERM settings[/color]

                      My xterm settings ?
                      [color=blue]
                      > - your readline and its bugs/features[/color]

                      Uh Uh ... I have disabled my $PYTHONSTARTUP script that
                      was using some features of the readline module, but
                      without any success ...
                      [color=blue]
                      > - your ~/.inputrc settings (see the readline man page)[/color]

                      INPUTRC refers to the default Mandrake settings in
                      etc/inputrc. An old version, 2002. It should be
                      mostly harmless, right <wink> ...
                      [color=blue]
                      > It's hard to say what's right and wrong really, and whose fault it is.
                      > I'm pretty sure it's not Python. What happens if you try bash?
                      >
                      > tuva:~> bash
                      > grahn@tuva:~$ echo -n 'foo'
                      > foograhn@tuva:~ $[/color]

                      Bash (into a konsole, same conditions than befor) seems to be ok:

                      [boisgera@meteor boisgera]$ echo -n 'foo'
                      foo[boisgera@meteor boisgera]$

                      :(

                      Cheers,

                      SB
                      [color=blue]
                      > /Jorgen
                      >
                      > --
                      > // Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
                      > \X/ algonet.se> R'lyeh wgah'nagl fhtagn![/color]

                      Comment

                      Working...