python嵌入c开发板,在C ++中嵌入Python

Good Morning Sir,

I have referred this article, Embedding Python program in a C/C++ code[^] I have followed up the tutorial and successfully embedded Python in my code.PyRun_SimpleString("print('Hello World from Embedded Python!!!')");

s used to execute a single line of Python code but how do I run a multiple lines of code in Python. I also tried running a Python from a file but the file also needed to be there for running the executable. Cry | :(( I dont want a file along with my executable, I searched in the google sir but I find no results.

I am confused here, I dont know what to doConfused | :confused:

Thank you sir for your time

What I have tried:

1. tried to contact the author of the article, waited for a month and he is unresponsive.

2. Tried some Googling but I don't find anything relevant, and I am still waiting for the author to respond.

Any help is much appreciated

Thank you sir for your time!

解决方案Well, you could simply turn the python file into binary and compile/link it into your program binary. At run time, take the compiled binary text (which should be some const char* at this point) and feed it to Python as a string.

This approach however, makes your application have to compile every time you need any Python changes... which loses a big part of the desirability of using Python in the first place. In another words... at that point why use Python at all?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值