- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to raise Python exception from a C extension?
For the above module, we need to prepare following setup.py script −
from distutils.core import setup, Extension setup(name='helloworld', version='1.0', \ ext_modules=[Extension('helloworld', ['hello.c'])])
Now, we use the following command,
$ python setup.py install
Once we install the extension, we would be able to import and call that extension in our Python script test.py and catch the exception in it as follows −
#test.py import helloworld try: print helloworld.helloworld() except Exception as e: print str(e)
This would produce the following result −
bad format char passed to Py_BuildValue
Advertisements
To Continue Learning Please Login
Login with Google