CPY3 - "Methods node

Trying to create a simple “Methods” node which takes in variables and returns methods for debugging on the back end.

I wanted to add the .Name of the variables in addition to the dir() but the exception to catch and report the error (name not found) doesn’t work…

def to_list(item_or_list=[]):
    return item_or_list if type(item_or_list) is list else [item_or_list]

x=to_list(IN[0])                  ##Covnert to list if single item
OUT=[]
for y in x:
    out=[]
    try:
        out.append(y.Name)
    except Exception, e:
        out.append(e.tostring())
    
    try:
        out.append(type(y))
    except Exception, e:                ##line#10 = Really won't let me do the "Exception, e" for some reason...
        out.append(e.ToString())

    OUT.append(out,dir(y))
      

image

this simple version works fine:

def to_list(item_or_list=[]):
    return item_or_list if type(item_or_list) is list else [item_or_list]

x=to_list(IN[0])                  ##Covnert to list if single item

OUT=[dir(y) for y in x]

image

You’re close. The syntax is just a little off. You need to get the exception with
except Exception as e:

Then you can return e as the exception (which is already a string).
image

2 Likes

Thank you - the Linkedin tutorial was incorrect : )

This works:

def to_list(item_or_list=[]):
    return item_or_list if type(item_or_list) is list else [item_or_list]

def GetMethods(x):
    OUT=[]
    for y in x:
        out=[]
        try:
            out.append(y.Name)
        except Exception as e:
            out.append(e)
        
        try:
            out.append(type(y))
        except Exception as e:
            out.append(e)
        
        OUT.append([out,"Methods:",dir(y)])
        
        try:
            y.name
            out.append(GetMethods(y))
        except:
            continue
    return OUT

x=to_list(IN[0])                  ##Covnert to list if single item

OUT=GetMethods(x)