unbuffering std streams in code

Discussion in 'Python' started by John Reese, May 28, 2005.

  1. John Reese

    John Reese Guest

    You know how you can specify that stderr, stdin, stdout should be
    unbuffered by running python with the -u switch? Is there any way I
    can have the same affect in code by doing something to the sys.std*
    variables?
     
    John Reese, May 28, 2005
    #1
    1. Advertisements

  2. John Reese wrote:

    > You know how you can specify that stderr, stdin, stdout should be
    > unbuffered by running python with the -u switch? Is there any way I
    > can have the same affect in code by doing something to the sys.std*
    > variables?


    try this:

    >>> import os, sys
    >>> sys.stdout = os.fdopen(sys.stdout.fileno(), sys.stdout.mode, 0)


    (repeat for the other streams)

    (-u does a bit more than this on some platforms, but the above
    should be good enough for many purposes)

    </F>
     
    Fredrik Lundh, May 28, 2005
    #2
    1. Advertisements

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.
Similar Threads
  1. Peter Jansson
    Replies:
    5
    Views:
    7,005
    Ivan Vecerina
    Mar 17, 2005
  2. Vinu
    Replies:
    4
    Views:
    555
    Jim Langston
    Jul 7, 2005
  3. Vinu
    Replies:
    0
    Views:
    499
  4. Dylan

    std string streams

    Dylan, Aug 9, 2005, in forum: C++
    Replies:
    5
    Views:
    369
    Joe Bacigalupa
    Aug 9, 2005
  5. Geoffrey S. Knauth
    Replies:
    6
    Views:
    1,309
    Earl Purple
    Jan 18, 2006
  6. puzzlecracker
    Replies:
    3
    Views:
    2,310
    Mike Wahler
    May 8, 2006
  7. Jeffrey Walton
    Replies:
    10
    Views:
    1,274
    Mathias Gaunard
    Nov 26, 2006
  8. , India
    Replies:
    3
    Views:
    3,536
    James Kanze
    Nov 13, 2010
Loading...