Possible Duplicate:
How can I use C++ class in Python?
I am designing a software in python but I am experiencing some memory problems while implementing it with python so I am planning to extend my software with C++. So I was thinking can I use C++ defined class and use it in python as Superclass and override some of its methods?
The super() function in Python makes class inheritance more manageable and extensible. The function returns a temporary object that allows reference to a parent class by the keyword super. The super() function has two major use cases: To avoid the usage of the super (parent) class explicitly.
__init__() of the superclass ( Square ) will be called automatically. super() returns a delegate object to a parent class, so you call the method you want directly on it: super(). area() . Not only does this save us from having to rewrite the area calculations, but it also allows us to change the internal .
__new__ is static class method, while __init__ is instance method. __new__ has to create the instance first, so __init__ can initialize it. Note that __init__ takes self as parameter. Until you create instance there is no self . Now, I gather, that you're trying to implement singleton pattern in Python.
In Python a class can inherit from more than one class. If a class inherits, it has the methods and variables from the parent classes. In essence, it's called multiple inheritance because a class can inherit from multiple classes. This is a concept from object orientated programming.
The answer is yes.
You can inherit and extend the class using boost.python. Please take a look how to do that.
However, to override the methods of base C++ class the way is bit more complex, please take a look at this article on the subject.
Also, I would have considered to think how to avoid using inheritance and use wrappers instead for your C++ class, if that is possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With