Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set sys.argv in a boost::python plugin

I use boost::python to integrate Python into a C++ program. Now I would like that the Python program that is executed via boost::python::exec_file() can obtain the command line arguments of my C++ program via sys.argv. Is this possible?

like image 762
peschü Avatar asked Mar 13 '26 08:03

peschü


1 Answers

Prior to your call to exec_file() (but after Py_Initialize(), you should invoke PySys_SetArgv(argc, argv); giving it the int argc and const char *argv[] from your program's main().

like image 88
Brian Cain Avatar answered Mar 14 '26 22:03

Brian Cain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!