[英]Pass Python variable to my C++ script and g++ invocation
In my Python script I run my C++ script using:在我的 Python 脚本中,我使用以下命令运行我的 C++ 脚本:
os.system('g++ -std=c++0x mutualcepepe.cpp -o mutualout')
It works, but I want to pass my Python changeable (user defines its value) variable to C++ in this command line, for example variable:它有效,但我想在此命令行中将我的 Python 可变(用户定义其值)变量传递给 C++,例如变量:
threshold = 1.33
(it can be also a string I can cast it to float in C++ script) (它也可以是一个字符串,我可以将它转换为在 C++ 脚本中浮动)
I tried even to pass the exact value:我什至试图传递确切的值:
os.system('g++ -std=c++0x mutualcepepe.cpp 1.33 -o mutualout')
or:或者:
os.system('g++ -std=c++0x mutualcepepe.cpp -o mutualout' 1.33)
but I still get the same error:但我仍然得到同样的错误:
g++: error: 1.33 (or threshold): No such file or directory
I searched for solutions on the net, but I didn't find an answer.我在网上搜索了解决方案,但没有找到答案。
I have other idea to put ONLY this value in other text file which I will open and get the value, but still want to to this a little bit more elegantly.我有其他想法只将这个值放在其他文本文件中,我将打开并获取该值,但仍然希望更优雅一点。
Is there a way to pass that variable which wouldn't be considered by g++
as a directory?有没有办法传递那个不会被g++
视为目录的变量?
You could use the -D
option to add a macro:您可以使用-D
选项添加宏:
g++ -D "threshold = 1.33" ...
then you would refer to the macro value threshold
in mutualcepepe.cpp
.那么您将参考mutualcepepe.cpp
的宏值threshold
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.