Menu

Can I build a list of inverse attribute in Ifcopensell?

2022-01-06
2022-01-06
  • Zhijian Jin

    Zhijian Jin - 2022-01-06

    I want to build a list for iterative try. The follows is a example code of methode list.

    def method1(arg):
        # do something
        return arg*1
    
    def method2(arg):
        # do something else
        return arg*2
    
    
    methods = [method1, method2]
    
    for m in methods:
        print(m(5))
    

    I want to write something like this. But not with methode in the list, but with inverse Attribute in the list.

    How can I get the name of all inverse attribute of a object, like IsDefinedBy of something?

    And how can I call the inverse attribute from a list? My plan is I get the name of the Inverse attribute from list, like IsDefinedBy. And call it in this part:

    for m in methods:
        print(m(5))
    
     
  • Zhijian Jin

    Zhijian Jin - 2022-01-06

    The first part how to get inverse attribute have thomas answered in my last post.
    the second part how to call the inverse attribut. Man can do it with object.getattr(inverse_attribute_name)

     
    • Thomas Krijnen

      Thomas Krijnen - 2022-01-06

      Have a look at getattr(obj, name, default) or operator.attrgetter

       

Log in to post a comment.