You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can use this project to combine c++ code and python code in one file.
How to use
1. Install
pip install combina_cpp_and_py
2. Use
Hypothesis that you have a cpp file named "test.cpp" and a python file named "test.py".
import combina_cpp_and_py
with open('test.cpp', 'r') as f:
cpp_code = f.read()
with open('test.py', 'r') as f:
py_code = f.read()
new_code = combina_cpp_and_py.combine(cpp_code, py_code)
with open('result.cpp', 'w') as f:
f.write(new_code)
with open('result.py', 'w') as f:
f.write(py_code)
3. Result
You will get a new cpp file named "result.cpp" and "result.py" which contains the combined c++ code and python code.
The code will be combined in the following way:
1. The c++ code will be placed in the {$cppcode} block.
2. The python code will be placed in the {$pythoncode} block.
3. When run c++, the {$pythoncode} block will be ignored due to "#if false" and "#endif".
4. When run python, the {$cppcode} block will be ignored due to "#" and " r"""""" ".
Warning
Don't use the code like the result code, or there will be ERROR due to special statement.