Syntax error when using "with open" in Python (python newbie)

Posted by Tony on Stack Overflow See other posts from Stack Overflow or by Tony
Published on 2010-04-21T17:22:11Z Indexed on 2010/04/21 17:23 UTC
Read the original article Hit count: 383

Filed under:
|
[root@234571-app2 git]# ./test.py 
  File "./test.py", line 4
    with open("/home/git/post-receive-email.log",'a') as log_file:
            ^
SyntaxError: invalid syntax

The code looks like this:

[root@234571-app2 git]# more test.py 
#!/usr/bin/python
from __future__ import with_statement

with open("/home/git/post-receive-email.log",'a') as log_file:
    log_file.write("hello world")

and I am using Python 2.5.5

[root@234571-app2 git]# python -V
Python 2.5.5

© Stack Overflow or respective owner

Related posts about python

Related posts about syntax-error