树莓派编程与输入输出接口全解析
1. Python调用C代码示例
在树莓派编程中,我们可以使用Python脚本调用C程序代码。以下是一个示例脚本 /chp05/boostPython/test.py :
#!/usr/bin/python
# A Python program that calls C program code
import erpi
print "Start of the Python program"
print erpi.hello("Derek")
val = erpi.integrate(0, 3.14159, 1000000)
print "The integral result is: ", val
print "End of the Python program"
执行该脚本后,输出结果如下:
pi@erpi ~/exploringrpi/chp05/boostPython $ ./test.py
Start of the Python program
Hello Derek!
The integral result is: 1.99999999999
End of the Python program
此外, timeit 测试结果约为3.225秒,这与Python/C API的性能一致。尽管 Boost.Python 占用空间较大,但由于其性能、简化的语法以及对C++类的支持,它是集成C/C++和Pyth
超级会员免费看
订阅专栏 解锁全文
51

被折叠的 条评论
为什么被折叠?



