Python Error trying to use namedtuple()

I’m trying to write a Python script that uses namedtuple(), this should be available in Maya 2015? PyMel even has it under utils. Yet when I try to import it, my IDE(JetBrains PyCharm) claims it’s never used, with or without the IDE says namedtuple is an unresolved reference. When I run the script within Maya 2015 I get the following error:

Error: NameError: file <maya console> line 149: name ‘namedtuple’ is not defined

The specific line of code is:

Quaternion = namedtuple(‘Quaternion’, ‘w x y z’)

All other imports and code seems to be fine, so I’m a bit confused what’s going on here.

you need to import namedtuple from the collections module before you can use it.


from collections import namedtuple
quat = namedtuple('Quaternion', 'w x y z') 

[QUOTE=rgkovach123;27044]you need to import namedtuple from the collections module before you can use it.


from collections import namedtuple
quat = namedtuple('Quaternion', 'w x y z') 

https://docs.python.org/dev/library/collections.html[/QUOTE]

Cheers for that, new to Python, saw those docs and the example code didn’t have an import statement for it, then I came across the PyMel one and confusion ensued :stuck_out_tongue:

if you are new to python, you should spend some time familiarizing yourself with the various built-in modules that come with python. By default, you import what you need.

[QUOTE=rgkovach123;27050]if you are new to python, you should spend some time familiarizing yourself with the various built-in modules that come with python. By default, you import what you need.[/QUOTE]

Yes I have with json and io.open. Just been quite a bit of info when switching from melscript, pymel, openmaya, api v1 & v2, another possible python option?, pyside/pyqt, 2.x 3.x, etc. Is there a reason Maya has switched to using pyside over pyqt?

Is there a reason Maya has switched to using pyside over pyqt?

Pretty sure its related to licensing issues, not technology.

Just take it slow, learn one thing at a time, and it will all make sense. Eventually. Sorta.