from __future__ import with_statement # works on both Python and Jython with open("/proc/sys/net/ipv4/ip_forward", "w") as f: f.write("1") # doesn't work with Jython with open("/sys/block/sdc/device/delete", "w") as f: f.write("1")