如何从C扩展引发Python异常?
对于上述模块,我们需要准备以下setup.py脚本-
from distutils.core import setup, Extension
setup(name='helloworld', version='1.0', \
ext_modules=[Extension('helloworld', ['hello.c'])])现在,我们使用以下命令,
$ python setup.py install
安装扩展后,我们将能够在Python脚本test.py中导入并调用该扩展,并在其中捕获异常,如下所示-
#test.py import helloworld try: print helloworld.helloworld() except Exception as e: print str(e)
这将产生以下结果-
bad format char passed to Py_BuildValue
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短