Skip to main content

Combina C++ and Python code

Project description

Combina c++ code and python code

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.
#if false
r"""
#endif
{$cppcode}
#if false
"""
{$pythoncode}
#endif

Explain

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"""""" ".
# 2025.5.8 v0.4.1

CHANGE

  • use different way to deal with special code

2025.5.7 v0.3.1

FIX

  • change the annotation in c++ code

2025.5.7 v0.3.0

ADD

  • add more special code

  • add more functions in combine.h

2025.5.6 v0.2.0

ADD

  • add warning when special code in the code block

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

combina_cpp_and_py-0.4.0.1.tar.gz (9.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

combina_cpp_and_py-0.4.0.1-py3-none-win_amd64.whl (13.8 kB view details)

Uploaded Python 3Windows x86-64

combina_cpp_and_py-0.4.0.1-py3-none-win32.whl (13.8 kB view details)

Uploaded Python 3Windows x86

File details

Details for the file combina_cpp_and_py-0.4.0.1.tar.gz.

File metadata

  • Download URL: combina_cpp_and_py-0.4.0.1.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for combina_cpp_and_py-0.4.0.1.tar.gz
Algorithm Hash digest
SHA256 e7fb62d3dd3d353fb4f42e075b8fea16b5a2e47438ba3631ee0b82c8a3edf37c
MD5 52919e681f78a3b02ac3c22dba8ab7d1
BLAKE2b-256 1d361c7e6c950706eae0e04ce4fe35bf2b5a2a496a23ddd891d5a2995a93e7d3

See more details on using hashes here.

File details

Details for the file combina_cpp_and_py-0.4.0.1-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for combina_cpp_and_py-0.4.0.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 7e61f81b7793047a12573089de7d5b0ae821a5a092ceba2a46b25ac8306cc7e6
MD5 cbc3b5d538c9f5f319a2481393e619e4
BLAKE2b-256 47f3f30fbb23f533110c8b0ec330a1fa0eaba134eb8ffd3be6232d40baf84ca3

See more details on using hashes here.

File details

Details for the file combina_cpp_and_py-0.4.0.1-py3-none-win32.whl.

File metadata

File hashes

Hashes for combina_cpp_and_py-0.4.0.1-py3-none-win32.whl
Algorithm Hash digest
SHA256 3d9d8a6feed5549e04a0fe51cb46b3be733449ed85fae685d1b000874e30aa0e
MD5 e833493bb9b80a224f7754a92f67a19c
BLAKE2b-256 aa14028f24d14e64640c6501c5f3b1ceb91cc7d4787c0c27474740becbbb1564

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page