我不同意接受的答案,似乎是的,即使在.pyd也可以访问源代码的内容。
让我们看一下如果出现错误会发生什么:
1)创建此文件:
whathappenswhenerror.pyx
A = 6
print 'hello'
print A
print 1/0 # this will generate an error
2)使用python setup.py build编译它:
setup.py
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules = cythonize("whathappenswhenerror.pyx"), include_dirs=[])
3)现在在标准python文件中导入.pyd文件:
testwhathappenswhenerror.py
import whathappenswhenerror
4)让我们用python testwhathappenswhenerror.py运行它。 这是输出:
hello
6
Traceback (most recent call last):
File "D:\testwhathappenswhenerror.py", line 1, in
import whathappenswhenerror
File "whathappenswhenerror.pyx", line 4, in init whathappenswhenerror (whathappe