View Full Version : python exec() in Maya 2009

03 March 2009, 08:59 PM
I have scripted python file, with code:



I have python 2.5.1 installed on my PC/win XP system....
And when I try to run code in outer interpreter:

def loadFile(dirToFile):
return data

...code works perfectly. 'Skeleton' dictionary is placed in globals() and so on.
BUT! I don't understand why if I use the same code in Maya 2009 it returns the syntax error:

# Error: ('invalid syntax', ('<string>', 1, 11, 'Skeleton={\r\n'))
# Traceback (most recent call last):
# File "<maya console>", line 2, in <module>
# File "<string>", line 1
# Skeleton={
# ^
# SyntaxError: invalid syntax

Why is that? I don't know where I am supposed to find problem 'root' even. Any advice?

Thanks anyway for listening :)

03 March 2009, 12:20 AM
it looks like your file is saved with windows newline characters: \r\n

It may be that Maya's python is built without universal newline support. try forcing the file to be opened with universal newline support, like this:

open(dirToFile, 'rU' )

see this for more info:

This is one of the many frustrating aspects of working with python on windows, where it is the "odd man out" on many standards. unix/linux/osx use just \n to represent a newline, whereas windows uses \r\n, and python, being born of unix, must be compiled with a flag that tells it to acknowledge window's method as valid newline delimters.


03 March 2009, 04:45 AM
BIG Thanks, Chadrik. It works perfectly :thumbsup:
I'm very-very frustrated about this, but nothing can be done.... Now I will try to keep this fact in mind.
Thanks again!

CGTalk Moderation
03 March 2009, 04:45 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.