Saturday, December 26, 2015

Python - "The Darker Side of type"

https://www.jeffknupp.com/blog/2013/12/28/improve-your-python-metaclasses-and-dynamic-classes-with-type/

That blog post has a great description of how the type keyword can be used for another purpose, creating new types.

Here's an example of the syntax: Foo = type(str('Foo'), (object, ), {})

This page has more details: http://python-3-patterns-idioms-test.readthedocs.org/en/latest/Metaprogramming.html

No comments:

Post a Comment