C,C ++接口与Python [英] C, C++ Interface with Python

查看:129
本文介绍了C,C ++接口与Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成长指数C ++ code。我有一些需要更改每个我跑我的code(不同的运行条件)的时间变量(主要是布尔)。我一直在使用,在过去的主(INT ARGC,CHAR *的argv [])函数的参数命令行输入做到了这一点。

I have c++ code that has grown exponential. I have a number of variables (mostly Boolean) that need to be changed for each time I run my code (different running conditions). I have done this using the argument command line inputs for the main( int argc, char* argv[]) function in the past.

由于这种方法已经成为累赘(我有18个不同的运行状况,因此18种不同的说法:-(),我想移动到与Python接口(如果需要的Bash)。理想情况下,我想codeA python脚本,在这里我设置的数据成员的值,然后运行code。

Since this method has become cumbersome (I have 18 different running conditions, hence 18 different argument :-( ), I would like to move to interfacing with python (if need be Bash ). Ideally I would like to code a python script, where I set the values of data members and then run the code.

有没有人有任何指针/信息,可以帮助我吗?更妙的是一个简单的$ C $例如CD或URL,我可以看看了。

Does anyone have a any pointer/information that could help me out? Better still a simple coded example or URL I could look up.

编辑从原题:

对不起,我不认为我是清楚我的问题。我不想使用主(INT ARGC,CHAR *的argv [])在C 功能++。代替的命令行上设置的变量。我可以使用Python来声明,在我的C ++ code初始化数据成员?

Sorry I don't think I was clear with my question. I don't want to use the main( int argc, char* argv[]) feature in c++. Instead of setting the variables on the command line. Can I use python to declare and initialize the data members in my c++ code?

再次感谢迈克

推荐答案

C / C ++和Python之间的接口是大量文件,并有几种不同的方法。但是,如果你只是设定值则可能是矫枉过正使用Python,这是对靠种地其关闭,以跨preTER自定义过程中的大规模行动更为适合。

Interfacing between C/C++ and Python is heavily documented and there are several different approaches. However, if you're just setting values then it may be overkill to use Python, which is more geared toward customising large operations within your process by farming it off to the interpreter.

我个人建议的研究INI文件的方法,无论是传统或通过使用XML,甚至更轻的脚本语言Lua的一样。

I would personally recommend researching an "ini" file method, either traditionally or by using XML, or even a lighter scripting language like Lua.

这篇关于C,C ++接口与Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆