Ulrich Eckhardt writes:
> Am 05.02.2013 01:09, schrieb Jabba Laci:
>> setting the sys.stdout back to the original value doesn't work.
> [...]
>> The problem is in __exit__ when sys.stdout is pointed to the old
>> value. sys.stdout.write doesn't work from then on. Output:
>>
>> .close failed
Am 05.02.2013 01:09, schrieb Jabba Laci:
I like the context manager idea
There is a helper library for constructing context managers, see
http://docs.python.org/2/library/contextlib.html. That would have made
your code even shorter.
setting the sys.stdout back to the original value doesn
Terry Reedy writes:
> It looks like you should perhaps just forget about reopening and just
> use sys.stdout.flush(). This works fine even on IDLE.
As an alternative, can't you just use sys.stderr for printing such
feedback? sys.stderr is unbuffered by default...
ciao, lele.
--
nickname: Lele
On 2/4/2013 7:09 PM, Jabba Laci wrote:
Hi,
Thanks for the answers. I like the context manager idea but setting
the sys.stdout back to the original value doesn't work.
Example:
class Unbuff(object):
def __init__(self):
self.stdout_bak = sys.stdout
This could/should go in the __e
Hi,
Thanks for the answers. I like the context manager idea but setting
the sys.stdout back to the original value doesn't work.
Example:
class Unbuff(object):
def __init__(self):
self.stdout_bak = sys.stdout
def __enter__(self):
sys.stdout.flush()
sys.stdout = os
On 2/4/2013 12:12 PM, Jabba Laci wrote:
Hi,
I'd like to set autoflush on/off in my script. I have a loop that is
checking something and every 5 second I want to print a '.' (dot). I
do it with sys.stdout.write and since there is no newline, it is
buffered and not visible immediately. I have this
Am 04.02.2013 18:12, schrieb Jabba Laci:
autoflush_on = False
def unbuffered():
"""Switch autoflush on."""
global autoflush_on
# reopen stdout file descriptor with write mode
# and 0 as the buffer size (unbuffered)
if not autoflush_on:
sys.stdout = os.fdopen(sys
Jabba Laci wrote:
> Hi,
>
> I'd like to set autoflush on/off in my script. I have a loop that is
> checking something and every 5 second I want to print a '.' (dot). I
> do it with sys.stdout.write and since there is no newline, it is
> buffered and not visible immediately.
My solution is sys.st