I have the following code which runs perfectly on Python 2.6.6:
import tempfile
with tempfile.NamedTemporaryFile() as scriptfile:
scriptfile.write(<variablename>)
scriptfile.flush()
subprocess.call(['/bin/bash', scriptfile.name])
However, when I try to run it on Python 2.4.3, I get the following error:
File "<stdin>", line 2
with tempfile.NamedTemporaryFile() as scriptfile
^
SyntaxError: invalid syntax
Is there a change in syntax in Python 2.4.3?
Python 2.4 does not support the
with
statement. So you just need to open and close thescriptfile
manually.