🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
Python - calling C++ function
Hi guys,
I have my second big python/c question:
How can I call C func from Python?
AND how can I use C++ class in python code? (if it is possible, i hope it is...)
How can I call C func from Python?
You expose it as an extension.
AND how can I use C++ class in python code?
The easy ways are to use either boost::python or SWIG.
The hard way is to manually define an extension type.
“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan
You expose it as an extension.
AND how can I use C++ class in python code?
The easy ways are to use either boost::python or SWIG.
The hard way is to manually define an extension type.
“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” — Brian W. Kernighan
Wow. I guess you really do learn a new thing every day. I didn't know you could call C++ stuff in Python.. that's pretty cool. Hmm, maybe python deserves a second glace ;)
- CD
- CD
I use Swig in my project and it works great, however it does have one serious flaw IMHO. When wrapping a C++ class in Python code (or any other language IIRC) then it creates a series of C-style functions and creates a Python class to wrap them.
This isn't a very nice way of doing it, and is a bit of a performance hit. I guess it stems from the olden days when you couldn't derive from a C type, but now that restriction has gone that is unneccessary.
Also Swig ignores namespaces, but that's not huge problem.
HTH,
Andrew
This isn't a very nice way of doing it, and is a bit of a performance hit. I guess it stems from the olden days when you couldn't derive from a C type, but now that restriction has gone that is unneccessary.
Also Swig ignores namespaces, but that's not huge problem.
HTH,
Andrew
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement