'with' Statement in Maya2009

Hi all,
I’m in the middle of finalizing a new tools pack prior to release and am having some issues getting it compliant with Maya2009 Python2.5

I’ve been using the ‘with’ statement and obviously in 2010 upwards it’s in by default with 2.6 Python. But I’m trying to get it running in 2009 by using the

from future import with_statement

but whatever I do Maya moans, looking like the future import didn’t work? Anybody shed any light on this? I’m getting the following error:


# <maya console>:2: Warning: 'with' will become a reserved keyword in Python 2.6
# Error: ('invalid syntax', ('<maya console>', 2, 9, 'with open(test, "r") as fileStream:
'))
#   File "<maya console>", line 1
#      with open(test, "r") as fileStream:
#              ^

thanks guys

Red

Hi,

I’m going with works for me…
Are you doing the import in the same scope as your ‘with’ call?

Keir

you need to put the from future statement at the very top of each script that uses the with statement.

its a pain, I know… we’re running dual 2009 and 2011 versions.

Hhhmm, my mistake, I forgot the import in the module I was testing, thought I’d patched them all!
In the script editor if you don’t run the future import statement along with the block you’re running it fails. I just assumed that the import would work as a normal import so I could run that first, then the code, that’s where it failed on me.

thanks guys