CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Sat, 26 Jul 2025 15:02:15 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20100330001020
location: https://web.archive.org/web/20100330001020/https://wiki.python.org/moin/boost.python/SimpleExample
server-timing: captures_list;dur=0.659987, exclusion.robots;dur=0.023792, exclusion.robots.policy;dur=0.010291, esindex;dur=0.013169, cdx.remote;dur=52.300416, LoadShardBlock;dur=142.289786, PetaboxLoader3.datanode;dur=58.165040
x-app-server: wwwb-app214
x-ts: 302
x-tr: 226
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: SERVER=wwwb-app214; path=/
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Sat, 26 Jul 2025 15:02:16 GMT
content-type: text/html; charset=utf-8
x-archive-orig-date: Tue, 30 Mar 2010 00:10:20 GMT
x-archive-orig-server: Apache/2.2.9 (Debian) mod_fastcgi/2.4.6 mod_python/3.3.1 Python/2.5.2 mod_wsgi/2.5
x-archive-orig-vary: Cookie,User-Agent,Accept-Language
x-archive-orig-content-length: 9404
x-archive-orig-connection: close
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Tue, 30 Mar 2010 00:10:20 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Sun, 07 May 2006 04:19:45 GMT", ; rel="prev memento"; datetime="Fri, 26 Feb 2010 20:59:16 GMT", ; rel="memento"; datetime="Tue, 30 Mar 2010 00:10:20 GMT", ; rel="next memento"; datetime="Thu, 23 Jun 2011 07:00:31 GMT", ; rel="last memento"; datetime="Fri, 27 Jun 2025 20:07:53 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: 51_15_20100329235900_crawl102-c/51_15_20100330000821_crawl103.arc.gz
server-timing: captures_list;dur=0.512773, exclusion.robots;dur=0.018509, exclusion.robots.policy;dur=0.009596, esindex;dur=0.011362, cdx.remote;dur=62.477816, LoadShardBlock;dur=181.093378, PetaboxLoader3.datanode;dur=108.524712, PetaboxLoader3.resolve;dur=638.329560, load_resource;dur=605.428156
x-app-server: wwwb-app214
x-ts: 200
x-tr: 888
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
content-encoding: gzip
boost.python/SimpleExample - PythonInfo Wiki
Suppose we have the following C++ API which we want to expose in Python:
#include <string> namespace { // Avoid cluttering the global namespace. // A couple of simple C++ functions that we want to expose to Python. std::string greet() { return "hello, world"; } int square(int number) { return number * number; } }
Here is the C++ code for a python module called getting_started1 which exposes the API.
#include <boost/python.hpp> using namespace boost::python; BOOST_PYTHON_MODULE(getting_started1) { // Add regular functions to the module. def("greet", greet); def("square", square); }
That's it! If we build this shared library and put it on our PYTHONPATH we can now access our C++ functions from Python.
>>> import getting_started1 >>> print getting_started1.greet() hello, world >>> number = 11 >>> print number, '*', number, '=', getting_started1.square(number) 11 * 11 = 121
EditText (last edited 2008-11-15 14:00:37 by localhost)