Search code examples
pythondequepython-2.5

Syntax Error with open(logPath, 'r') as fh:


with open(logPath, 'r') as fh:
    for line in TailDeque(fh, 20):
        gamethread.delayed(0, show_recentlyCommands, (userid, text))   

I always get an Error in the line with open(logPath, 'r') as fh:

I'm using Python 2.5 and using the TailDeque.


Solution

  • Python 2.5 supports the with statement only optionally; you need to have this as the first line in each file that uses the with statement:

    from __future__ import with_statement
    

    The with statement works without __future__ import since Python 2.6