Popular recipes by Ahmet Emre Aladağ http://code.activestate.com/recipes/users/4174877/2013-07-18T10:02:59-07:00ActiveState Code RecipesExtending non-extendable C++ based Python classes (Python)
2013-07-18T10:02:59-07:00Ahmet Emre Aladağhttp://code.activestate.com/recipes/users/4174877/http://code.activestate.com/recipes/578576-extending-non-extendable-c-based-python-classes/
<p style="color: grey">
Python
recipe 578576
by <a href="/recipes/users/4174877/">Ahmet Emre Aladağ</a>
(<a href="/recipes/tags/attribute/">attribute</a>, <a href="/recipes/tags/proxy/">proxy</a>, <a href="/recipes/tags/subclass/">subclass</a>).
Revision 2.
</p>
<p>graph_tool library is based on boost C++ library and provides Vertex class binding for Python. If we wanted to extend this Vertex class and add some attributes and methods, it wouldn't let us do that due to private constructor in C++ code (RuntimeError: This class cannot be instantiated from Python). We can overcome this obstacle using Proxy pattern.</p>
<p>In the __getattr__ method, if the attribute(or function name) is not in the Subclass MyVertex, then it looks for attributes of Vertex object that is defined inside MyVertex.</p>
Keyword Argument Injection with Python Decorators (Python)
2010-09-05T17:06:04-07:00Ahmet Emre Aladağhttp://code.activestate.com/recipes/users/4174877/http://code.activestate.com/recipes/577382-keyword-argument-injection-with-python-decorators/
<p style="color: grey">
Python
recipe 577382
by <a href="/recipes/users/4174877/">Ahmet Emre Aladağ</a>
(<a href="/recipes/tags/class/">class</a>, <a href="/recipes/tags/class_decorator/">class_decorator</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/injection/">injection</a>, <a href="/recipes/tags/variable/">variable</a>).
Revision 2.
</p>
<p>In most of the object oriented codes we write, we need to set class attributes to the given argument values and this is a very line-consuming thing. To get over these redundant lines, I found a solution using decorators. </p>