diff --git a/doc/html/index.html b/doc/html/index.html index be50f11b..85426fd1 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -126,7 +126,7 @@
Last revised: April 18, 2018 at 01:55:50 GMT |
+Last revised: July 11, 2018 at 23:40:09 GMT |
Last revised: April 18, 2018 at 01:55:56 GMT |
+Last revised: July 11, 2018 at 23:40:14 GMT |
Last revised: April 18, 2018 at 01:55:53 GMT |
+Last revised: July 11, 2018 at 23:40:12 GMT |
- You can even add a little syntactic sugar with the use of metaclasses. Let's - create a special metaclass that "injects" methods in other classes. -
-# The one Boost.Python uses for all wrapped classes. -# You can use here any class exported by Boost instead of "point" -BoostPythonMetaclass = point.__class__ - -class injector(object): - class __metaclass__(BoostPythonMetaclass): - def __init__(self, name, bases, dict): - for b in bases: - if type(b) not in (self, type): - for k,v in dict.items(): - setattr(b,k,v) - return type.__init__(self, name, bases, dict) - -# inject some methods in the point foo -class more_point(injector, point): - def __repr__(self): - return 'Point(x=%s, y=%s)' % (self.x, self.y) - def foo(self): - print 'foo!' --
- Now let's see how it got: -
->>> print point() -Point(x=10, y=10) ->>> point().foo() -foo! -
Another useful idea is to replace constructors with factory functions: