- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
- Related Articles
- How to raise an exception in Python?
- How do I manually throw/raise an exception in Python?
- Where's the standard python exception list for programmers to raise?
- How to raise an exception in one except block and catch it in a later except block in Python?
- How to change file extension in Python?
- How to extract file extension using Python?
- How To Raise a "File Download" Dialog Box in Python?
- Raise a polynomial to a power in Python
- How to throw a C++ exception?
- Raise a Hermite series to a power in Python
- Raise a Laguerre series to a power in Python
- Raise a Legendre series to a power in Python
- Raise a Hermite_e series to a power in Python
- Raise a Chebyshev series to a power in Python
- How to handle a python exception within a loop?

Advertisements