Beer glass scene creation
This course contains a little bit of everything with modeling, UVing, texturing and dynamics in Maya, as well as compositing multilayered EXR's in Photoshop.
# 1 21-07-2020 , 05:37 AM
Registered User
Join Date: May 2020
Posts: 2

some python function is not working in maya?

hi, i am new to python ... recently i had watched some tutorial about python. and i try it, it work in IDLE but when i apply in MAYA it doesn't work... am i doing wrong?

the sample given in tutorial :
s = [1, 2, 3, 4, 5]
a, *b, c = s
>>a
1
..b
2, 3, 4
>>c
5


and here what i tried in maya2018:
import maya.cmds as cmds
selObj = cmds.ls(sl=1) #(i did select few item in maya)
a,*b = selObj
print (a)

and i get # Error: invalid syntax #

thanks in advance for spending timeuser added image

# 2 03-09-2020 , 10:02 AM
Registered User
Join Date: Sep 2020
Posts: 5
Asterisk (*) unpacking is introduced in python 3 , Maya still uses python 2 so this method won't work
Instead you can use this code:
import maya.cmds as cmds
selObj = cmds.ls(sl=1)
a,b = selObj[0],selObj[1:]
print a
print b

# 3 27-07-2021 , 06:38 AM
Registered User
Join Date: Jul 2021
Posts: 1
Its because in Python 3, print statement has been replaced with a print() function, with keyword arguments to replace most of the special syntax of the old print statement. But if you write this in a program and someone using Python 2.x tries to run it, they will get an error. To avoid this, it is a good practice to import print function:

from __future__ import print_function

Now your code works on both python2 and python3

Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads