If one replaces sys.stdout with a custom stream, progress-table does still output to the old stream (usually standard out), even if the table is created and initialized AFTER the stream has been replaced.
The reason for this is the default argument file=sys.stdout, that gets evaluated when the module is imported for the first time and NOT when an actual table object is created. This can be hard to spot!
Suggested Solution
Replace the default argument with file=None and set it to sys.stdout in the constructor. This delays the evaluation of sys.stdout to the time at which a table object is actually created.
Even better: Officially accept None values for file as part of the interface and, in that case, retrieve sys.stdout on each write/flush instead of on object creation. This would allow one to redirect the output of progress-table even long after a table object has been created. The old behavior, i.e. sticking to a single, specific stream for all eternity, can still be achieved by explicitly passing file=sys.stdout to the constructor.
Problem
If one replaces
sys.stdout
with a custom stream, progress-table does still output to the old stream (usually standard out), even if the table is created and initialized AFTER the stream has been replaced.The reason for this is the default argument file=sys.stdout, that gets evaluated when the module is imported for the first time and NOT when an actual table object is created. This can be hard to spot!
Suggested Solution
Replace the default argument with
file=None
and set it tosys.stdout
in the constructor. This delays the evaluation ofsys.stdout
to the time at which a table object is actually created.Even better: Officially accept
None
values forfile
as part of the interface and, in that case, retrievesys.stdout
on each write/flush instead of on object creation. This would allow one to redirect the output of progress-table even long after a table object has been created. The old behavior, i.e. sticking to a single, specific stream for all eternity, can still be achieved by explicitly passingfile=sys.stdout
to the constructor.