CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Sat, 19 Jul 2025 18:20:48 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20110827012035
location: https://web.archive.org/web/20110827012035/https://wiki.python.org/moin/boost.python/SimpleExample
server-timing: captures_list;dur=0.513429, exclusion.robots;dur=0.024021, exclusion.robots.policy;dur=0.014520, esindex;dur=0.010042, cdx.remote;dur=33.700405, LoadShardBlock;dur=218.131569, PetaboxLoader3.datanode;dur=116.547643
x-app-server: wwwb-app201
x-ts: 302
x-tr: 281
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: SERVER=wwwb-app201; 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, 19 Jul 2025 18:20:48 GMT
content-type: text/html; charset=utf-8
x-archive-orig-date: Sat, 27 Aug 2011 01:20:35 GMT
x-archive-orig-server: Apache/2.2.16 (Debian)
x-archive-orig-vary: Cookie,User-Agent,Accept-Language
x-archive-orig-set-cookie: MOIN_SESSION_80_ROOT_moin=93b7a7419f85b7d5ab6eb5ed891a11e2cbb324e8; expires=Sat, 27-Aug-2011 02:20:00 GMT; Max-Age=3600; Path=/
x-archive-orig-content-length: 10676
x-archive-orig-connection: close
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Sat, 27 Aug 2011 01:20:35 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="Tue, 26 Jul 2011 21:06:25 GMT", ; rel="memento"; datetime="Sat, 27 Aug 2011 01:20:35 GMT", ; rel="next memento"; datetime="Fri, 21 Oct 2011 17:18:39 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: alexa-web-20110907191700-00050/51_23_20110827012000_crawl103.arc.gz
server-timing: captures_list;dur=0.674522, exclusion.robots;dur=0.029886, exclusion.robots.policy;dur=0.017691, esindex;dur=0.013695, cdx.remote;dur=10.054224, LoadShardBlock;dur=89.870821, PetaboxLoader3.datanode;dur=175.767284, load_resource;dur=242.601551, PetaboxLoader3.resolve;dur=138.433306
x-app-server: wwwb-app201
x-ts: 200
x-tr: 407
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=1
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
User
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
boost.python/SimpleExample (last edited 2008-11-15 14:00:37 by localhost)