Discussion:
[Maya-Python] list on return has difference with print
delibrax
2018-10-05 14:45:16 UTC
Permalink
Hi guys, I have function here :

def arrayBPMFolder(obj):
for i in obj:
#print i
relatives = mc.listRelatives(i, p=True, f=True)
#print relatives
for o in relatives:

objs = o.split('|')[-2]
print objs
#return objs

when i *printed* *objs *the result is :

bindCyl03CtrlBPM_grp
bindCyl02CtrlBPM_grp
bindCyl01CtrlBPM_grp
bindCylBase01JntBPM_grp

but then when i *return* *objs *only shown result as bindCyl03CtrlBPM_grp.

any insight? Thanks in advance! :)
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/05756fc2-17a1-4dfe-b49f-2760cf82b87c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
delibrax
2018-10-05 14:48:07 UTC
Permalink
So I need to get return as similar like print results. How to do that?
Post by delibrax
#print i
relatives = mc.listRelatives(i, p=True, f=True)
#print relatives
objs = o.split('|')[-2]
print objs
#return objs
bindCyl03CtrlBPM_grp
bindCyl02CtrlBPM_grp
bindCyl01CtrlBPM_grp
bindCylBase01JntBPM_grp
but then when i *return* *objs *only shown result as bindCyl03CtrlBPM_grp.
any insight? Thanks in advance! :)
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/e29b63e7-517e-4afa-b0ba-bf14c49f6247%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Justin Israel
2018-10-05 19:05:11 UTC
Permalink
Post by delibrax
So I need to get return as similar like print results. How to do that?
You want to build up a list of your results over the course of the loop and
then return that.

def arrayBPMFolder(obj):
results = []

for i in obj:
relatives = mc.listRelatives(i, p=True, f=True)

for o in relatives:
objs = o.split('|')[-2]
results += objs

return results
Post by delibrax
Post by delibrax
#print i
relatives = mc.listRelatives(i, p=True, f=True)
#print relatives
objs = o.split('|')[-2]
print objs
#return objs
bindCyl03CtrlBPM_grp
bindCyl02CtrlBPM_grp
bindCyl01CtrlBPM_grp
bindCylBase01JntBPM_grp
but then when i *return* *objs *only shown result as
bindCyl03CtrlBPM_grp.
any insight? Thanks in advance! :)
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/e29b63e7-517e-4afa-b0ba-bf14c49f6247%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/e29b63e7-517e-4afa-b0ba-bf14c49f6247%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3eQaLD41RRPWdCsYKLYxoqymC8dpJq_qG54A7%3DfG7S9w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Justin Israel
2018-10-05 19:07:42 UTC
Permalink
Post by Justin Israel
Post by delibrax
So I need to get return as similar like print results. How to do that?
You want to build up a list of your results over the course of the loop
and then return that.
results = []
relatives = mc.listRelatives(i, p=True, f=True)
objs = o.split('|')[-2]
results += objs
return results
Sorry. I had a typo. That's what I get for answering with code from my
phone ;)

We want to append a single item to the list each time. Not add a list to a
list.

def arrayBPMFolder(obj):
results = []

for i in obj:
relatives = mc.listRelatives(i, p=True, f=True)

for o in relatives:
objs = o.split('|')[-2]
results.append(objs)

return results
Post by Justin Israel
Post by delibrax
Post by delibrax
#print i
relatives = mc.listRelatives(i, p=True, f=True)
#print relatives
objs = o.split('|')[-2]
print objs
#return objs
bindCyl03CtrlBPM_grp
bindCyl02CtrlBPM_grp
bindCyl01CtrlBPM_grp
bindCylBase01JntBPM_grp
but then when i *return* *objs *only shown result as
bindCyl03CtrlBPM_grp.
any insight? Thanks in advance! :)
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/e29b63e7-517e-4afa-b0ba-bf14c49f6247%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/e29b63e7-517e-4afa-b0ba-bf14c49f6247%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2TRJVTFq%3D%3DKnBpj05VqD8DiBH8u6O7rsFN3uSP1fJSnA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
delibrax
2018-10-06 04:09:18 UTC
Permalink
Hi Justin,

Solved.. Thank you! :)
Post by Justin Israel
Post by Justin Israel
Post by delibrax
So I need to get return as similar like print results. How to do that?
You want to build up a list of your results over the course of the loop
and then return that.
results = []
relatives = mc.listRelatives(i, p=True, f=True)
objs = o.split('|')[-2]
results += objs
return results
Sorry. I had a typo. That's what I get for answering with code from my
phone ;)
We want to append a single item to the list each time. Not add a list to a
list.
results = []
relatives = mc.listRelatives(i, p=True, f=True)
objs = o.split('|')[-2]
results.append(objs)
return results
Post by Justin Israel
Post by delibrax
Post by delibrax
#print i
relatives = mc.listRelatives(i, p=True, f=True)
#print relatives
objs = o.split('|')[-2]
print objs
#return objs
bindCyl03CtrlBPM_grp
bindCyl02CtrlBPM_grp
bindCyl01CtrlBPM_grp
bindCylBase01JntBPM_grp
but then when i *return* *objs *only shown result as
bindCyl03CtrlBPM_grp.
any insight? Thanks in advance! :)
--
You received this message because you are subscribed to the Google
Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send
<javascript:>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/e29b63e7-517e-4afa-b0ba-bf14c49f6247%40googlegroups.com
<https://groups.google.com/d/msgid/python_inside_maya/e29b63e7-517e-4afa-b0ba-bf14c49f6247%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/68e0c023-8f6b-4756-88e1-30176f5e1cd6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...