Menu

'with' statement in code analysis?

Jakob Malm
2011-04-29
2013-03-15
  • Jakob Malm

    Jakob Malm - 2011-04-29

    The following code yields a number of errors in pydev code analysis:

    with open('tmp.txt', 'w') as file:
        pass
    

    I get "undefined variable" for 'with' and 'as', and that 'open' was unexpected. My eclipse project is set to use Python 2.5 grammar.

    Is the above construct not supported in pydev? Or am I doing something wrong?

     
  • Fabio Zadrozny

    Fabio Zadrozny - 2011-04-29

    Python 2.5 doesn't support the with statement unless you add an import for it (Python 2.6 onwards doesn't require it):

    from __future__ import with_statement

    Cheers,

    Fabio

     
  • Jakob Malm

    Jakob Malm - 2011-04-29

    Ah. Thanks!

    I was running this code on python 2.6, so I didn't get an error. Importing with_statement from the future solved the issue. ;-)

     
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.