wlst - How can i override print function in Python 2.2.1 (WebLogic version) -
how override print function in python 2.2 in order being able redirect output custom logger.
i don't have version of 2.2 check (why using such old version?), suspect following valid 2.x.
the print
statement recognizes first argument beginning >>
indicate file write to.
the following identical:
print "foo", "bar" print >>sys.stdout, "foo", "bar"
as such, can specify file
object target file.
f = open("log.txt", "w") print >>f, "foo", "bar"
if want redirect every print
statement (or @ least ones aren't using specific file shown above), can replace sys.stdout
desired file.
sys.stdout = open("log.txt", "w") print "foo", "bar" # goes log.txt
if need it, original standard output still available via sys.__stdout__
.
Comments
Post a Comment