Does Python have something like anonymous inner classes of Java?

You can use the type(name, bases, dict) builtin function to create classes on the fly. For example:

op = type("MyOptionParser", (OptionParser,object), {"foo": lambda self: "foo" })
op().foo()

Since OptionParser isn’t a new-style class, you have to explicitly include object in the list of base classes.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)