Python: Find all subclasses of a class

0 comments

I would have thought there was some trickery or magic to this, or some sort of hidden Django function/signal to use.

But NOPE! With Python, it's a one line wonder!

# Get all subclasses for class
type.__subclasses__(Subscription)

That's it! Best part is there's no special imports to do, "type" is already a built-in, so it's available anywhere at any time.

Cpv5G
High 5's all round, fuck yeah!

Related Posts

0 comments:

Post a Comment

Leave your thoughts ...
---
If you are having trouble with copy/pasting in comments, you need to sign in or click 'Preview'. For more information about this Firefox bug, see here.

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog