list on return has difference with print

27 views
Skip to first unread message

delibrax

unread,
Oct 5, 2018, 10:45:16 AM10/5/18
to Python Programming for Autodesk Maya
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! :)

delibrax

unread,
Oct 5, 2018, 10:48:07 AM10/5/18
to Python Programming for Autodesk Maya
So I need to get return as similar like print results. How to do that?

Justin Israel

unread,
Oct 5, 2018, 3:05:29 PM10/5/18
to python_in...@googlegroups.com


On Sat, Oct 6, 2018, 3:48 AM delibrax <adien....@gmail.com> wrote:
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


--
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_m...@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

unread,
Oct 5, 2018, 3:07:58 PM10/5/18
to python_in...@googlegroups.com


On Sat, Oct 6, 2018, 8:05 AM Justin Israel <justin...@gmail.com> wrote:


On Sat, Oct 6, 2018, 3:48 AM delibrax <adien....@gmail.com> wrote:
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


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

delibrax

unread,
Oct 6, 2018, 12:09:19 AM10/6/18
to Python Programming for Autodesk Maya
Hi Justin,

Solved.. Thank you! :)
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages