I'm backporting a modern python script to 2.4 to make it compatible with stock RHEL 5.X. While most of the work has been fairly straight-forward, I can't figure out how to handle this case where I am appending to a file:
The syntax is pretty awful:
print >> file('/tmp/bar', 'ab'), 'Foo'
Though of course you should rather write:
f = open('/tmp/bar', 'ab') try: print >> f, 'Foo' finally: f.close()
to make sure that the output is actually closed and flushed. (Python 2.4 doesn't have
As an alternative to converting everything to
print_ function from the Six: Python 2 and 3 Compatibility Library. I am not sure whether the whole library supports 2.4 any longer, but that one function should be OK in 2.4.