how do i disable buffered output, like Perl's '$|=1'?

Moshe Zadka moshez at zadka.site.co.il
Sun Jan 14 21:31:52 EST 2001


On Sun, 14 Jan 2001 17:58:52 +0100, "floR" <flor_pino at hotmail.com> wrote:
> I can't find anywhere how I can disable 'buffered output', or whatever it is
> called.
> In Perl, you simply say $|=1, but in Python?
> Can anyone help me?

If you want to flush, you can use fp.flush()
(E.g., sys.stdout.flush()).

If you want stdout to autoflush you can do:

class AutoFlusher:

	def __init__(self, fp):
		self.fp = fp

	def write(self, s):
		self.fp.write(s)
		self.fp.flush()

	def writelines(self, lines):
		self.fp.writelines(lines)
		self.fp.flush()

sys.stdout = AutoFlusher(sys.stdout)
-- 
Moshe Zadka <sig at zadka.site.co.il>
This is a signature anti-virus. 
Please stop the spread of signature viruses!




More information about the Python-list mailing list