class.__subclasses__() trick

60 views
Skip to first unread message

Gregor

unread,
Mar 29, 2010, 6:32:38 PM3/29/10
to lithosphere
hi,

just saw your project on reddit. looks really nice. i needed to make a
similar
framework which involved nodes and connecting them. i found this
little trick
to register nodes. maybe you can use it in your project.

cheers gregor

class Node(object):
pass

class Mix(Node):
pass

class Simplex(Node):
pass

def node_registry():
nodes = {}
for n in Node.__subclasses__():
nodes[n.__name__] = n
return nodes


if __name__ == "__main__":
print node_registry()

Florian Bösch

unread,
Mar 30, 2010, 3:35:47 AM3/30/10
to lithosphere
On Mar 30, 12:32 am, Gregor <burger.gre...@gmail.com> wrote:
>         for n in Node.__subclasses__():
>                 nodes[n.__name__] = n

That's a nice idea, I'll probably use it, thanks! :)

Reply all
Reply to author
Forward
0 new messages