CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Fri, 18 Jul 2025 21:07:46 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20071208115909
location: https://web.archive.org/web/20071208115909/https://wiki.python.org/moin/boost%2Epython/SimpleExample
server-timing: captures_list;dur=0.686680, exclusion.robots;dur=0.027201, exclusion.robots.policy;dur=0.016437, esindex;dur=0.014668, cdx.remote;dur=19.131875, LoadShardBlock;dur=326.201238, PetaboxLoader3.datanode;dur=163.474652, PetaboxLoader3.resolve;dur=74.339185
x-app-server: wwwb-app200
x-ts: 302
x-tr: 371
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: SERVER=wwwb-app200; 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: Fri, 18 Jul 2025 21:07:48 GMT
content-type: text/html;charset=utf-8
x-archive-orig-date: Sat, 08 Dec 2007 11:59:09 GMT
x-archive-orig-server: Apache/2.0.54 (Debian GNU/Linux) mod_fastcgi/2.4.2
x-archive-orig-connection: close
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Sat, 08 Dec 2007 11:59:09 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="Wed, 08 Aug 2007 17:41:04 GMT", ; rel="memento"; datetime="Sat, 08 Dec 2007 11:59:09 GMT", ; rel="next memento"; datetime="Tue, 11 Mar 2008 00:39:40 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: 52_1_20071208104348_crawl102-c/52_1_20071208115619_crawl107.arc.gz
server-timing: captures_list;dur=1.122881, exclusion.robots;dur=0.052218, exclusion.robots.policy;dur=0.033178, esindex;dur=0.022134, cdx.remote;dur=7.455789, LoadShardBlock;dur=794.051056, PetaboxLoader3.datanode;dur=835.652287, load_resource;dur=416.613061, PetaboxLoader3.resolve;dur=345.446054
x-app-server: wwwb-app200
x-ts: 200
x-tr: 1266
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
boost.python/SimpleExample
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 2002-11-15 19:38:01 by MikeRovner)
DeleteCache (cached 2007-12-04 23:38:42)- Login
- Navigation
- Actions
- Your recent pages