2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-26 06:42:27 +00:00
Files
python/doc/tutorial/doc/html/index.html
Joel de Guzman 164e517a54 move to quickbook (WIP)
[SVN r25136]
2004-09-16 05:47:55 +00:00

31 lines
9.9 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 1. Boost.Boost Python 1.0</title><link rel="stylesheet" href="boostbook.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="Chapter 1. Boost.Boost Python 1.0"><link rel="next" href="boost_python.hello.html" title=" Building Hello World"><link rel="chapter" href="index.html" title="Chapter 1. Boost.Boost Python 1.0"><link rel="section" href="index.html#boost_python.quickstart" title="QuickStart"><link rel="section" href="boost_python.hello.html" title=" Building Hello World"><link rel="section" href="boost_python.exposing.html" title=" Exposing Classes"><link rel="section" href="boost_python.functions.html" title="Functions"><link rel="section" href="boost_python.object.html" title=" Object Interface"><link rel="section" href="boost_python.embedding.html" title="Embedding"><link rel="section" href="boost_python.iterators.html" title="Iterators"><link rel="section" href="boost_python.exception.html" title=" Exception Translation"><link rel="section" href="boost_python.techniques.html" title=" General Techniques"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table cellpadding="2" width="100%"><td valign="top"><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" width="277" height="86"></td><td align="center"><a href="../../index.htm">Home</a></td><td align="center"><a href="libraries.html">Libraries</a></td><td align="center"><a href="../../people/people.htm">People</a></td><td align="center"><a href="../../more/faq.htm">FAQ</a></td><td align="center"><a href="../../more/index.htm">More</a></td></table><hr><div class="spirit-nav"><a accesskey="n" href="boost_python.hello.html"><img src="images/next.png" alt="Next"></a></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="boost_python"></a>Chapter 1. Boost.Boost Python 1.0</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Joel</span> <span class="surname">de Guzman</span></h3></div></div><div><div class="author"><h3 class="author"><span class="firstname"></span> <span class="surname">David Abrahams</span></h3></div></div><div><p class="copyright">Copyright © 2002-2004 Joel de Guzman, David Abrahams</p></div><div><div class="legalnotice"><p>Distributed under the Boost Software License, Version 1.0.
(See accompanying file <tt class="filename">LICENSE_1_0.txt</tt> or copy at
<a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
</p></div></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="section"><a href="index.html#boost_python.quickstart">QuickStart</a></span></dt><dt><span class="section"><a href="boost_python.hello.html"> Building Hello World</a></span></dt><dt><span class="section"><a href="boost_python.exposing.html"> Exposing Classes</a></span></dt><dd><dl><dt><span class="section"><a href="boost_python.exposing.html#boost_python.constructors">Constructors</a></span></dt><dt><span class="section"><a href="boost_python.exposing.html#boost_python.class_data_members">Class Data Members</a></span></dt><dt><span class="section"><a href="boost_python.exposing.html#boost_python.class_properties">Class Properties</a></span></dt><dt><span class="section"><a href="boost_python.exposing.html#boost_python.inheritance">Inheritance</a></span></dt><dt><span class="section"><a href="boost_python.exposing.html#boost_python.class_virtual_functions">Class Virtual Functions</a></span></dt><dt><span class="section"><a href="boost_python.exposing.html#boost_python.deriving_a_python_class">Deriving a Python Class</a></span></dt><dt><span class="section"><a href="boost_python.exposing.html#boost_python.virtual_functions_with_default_implementations">Virtual Functions with Default Implementations</a></span></dt><dt><span class="section"><a href="boost_python.exposing.html#boost_python.class_operators_special_functions">Class Operators/Special Functions</a></span></dt></dl></dd><dt><span class="section"><a href="boost_python.functions.html">Functions</a></span></dt><dd><dl><dt><span class="section"><a href="boost_python.functions.html#boost_python.call_policies">Call Policies</a></span></dt><dt><span class="section"><a href="boost_python.functions.html#boost_python.overloading">Overloading</a></span></dt><dt><span class="section"><a href="boost_python.functions.html#boost_python.default_arguments">Default Arguments</a></span></dt><dt><span class="section"><a href="boost_python.functions.html#boost_python.auto_overloading">Auto-Overloading</a></span></dt></dl></dd><dt><span class="section"><a href="boost_python.object.html"> Object Interface</a></span></dt><dd><dl><dt><span class="section"><a href="boost_python.object.html#boost_python.basic_interface">Basic Interface</a></span></dt><dt><span class="section"><a href="boost_python.object.html#boost_python.derived_object_types">Derived Object types</a></span></dt><dt><span class="section"><a href="boost_python.object.html#boost_python.extracting_c___objects">Extracting C++ objects</a></span></dt><dt><span class="section"><a href="boost_python.object.html#boost_python.enums">Enums</a></span></dt></dl></dd><dt><span class="section"><a href="boost_python.embedding.html">Embedding</a></span></dt><dd><dl><dt><span class="section"><a href="boost_python.embedding.html#boost_python.using_the_interpreter">Using the interpreter</a></span></dt></dl></dd><dt><span class="section"><a href="boost_python.iterators.html">Iterators</a></span></dt><dt><span class="section"><a href="boost_python.exception.html"> Exception Translation</a></span></dt><dt><span class="section"><a href="boost_python.techniques.html"> General Techniques</a></span></dt><dd><dl><dt><span class="section"><a href="boost_python.techniques.html#boost_python.creating_packages">Creating Packages</a></span></dt><dt><span class="section"><a href="boost_python.techniques.html#boost_python.extending_wrapped_objects_in_python">Extending Wrapped Objects in Python</a></span></dt><dt><span class="section"><a href="boost_python.techniques.html#boost_python.reducing_compiling_time">Reducing Compiling Time</a></span></dt></dl></dd></dl></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="boost_python.quickstart"></a>QuickStart</h2></div></div><div></div></div><p>
The Boost Python Library is a framework for interfacing Python and
C++. It allows you to quickly and seamlessly expose C++ classes
functions and objects to Python, and vice-versa, using no special
tools -- just your C++ compiler. It is designed to wrap C++ interfaces
non-intrusively, so that you should not have to change the C++ code at
all in order to wrap it, making Boost.Python ideal for exposing
3rd-party libraries to Python. The library's use of advanced
metaprogramming techniques simplifies its syntax for users, so that
wrapping code takes on the look of a kind of declarative interface
definition language (IDL).</p><a name="quickstart.hello_world"></a><h2><a name="id343260"></a>Hello World</h2><p>
Following C/C++ tradition, let's start with the "hello, world". A C++
Function:</p><pre class="programlisting"><tt class="literal"><span class="keyword"> char</span><span class="keyword"> const</span><span class="special">*</span><span class="identifier"> greet</span><span class="special">()</span><span class="special">
{</span><span class="keyword">
return</span><span class="string"> "hello, world"</span><span class="special">;</span><span class="special">
}</span></tt></pre><p>
can be exposed to Python by writing a Boost.Python wrapper:</p><pre class="programlisting"><tt class="literal"><span class="preprocessor"> #include</span><span class="special"> &lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span><span class="keyword">
using</span><span class="keyword"> namespace</span><span class="identifier"> boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">;</span><span class="identifier">
BOOST_PYTHON_MODULE</span><span class="special">(</span><span class="identifier">hello</span><span class="special">)</span><span class="special">
{</span><span class="identifier">
def</span><span class="special">(</span><span class="string">"greet"</span><span class="special">,</span><span class="identifier"> greet</span><span class="special">);</span><span class="special">
}</span></tt></pre><p>
That's it. We're done. We can now build this as a shared library. The
resulting DLL is now visible to Python. Here's a sample Python session:</p><pre class="programlisting"><tt class="literal"><span class="special"> &gt;&gt;&gt;</span><span class="identifier"> import</span><span class="identifier"> hello</span><span class="special">
&gt;&gt;&gt;</span><span class="identifier"> print</span><span class="identifier"> hello</span><span class="special">.</span><span class="identifier">greet</span><span class="special">()</span><span class="identifier">
hello</span><span class="special">,</span><span class="identifier"> world</span></tt></pre><div class="blockquote"><blockquote class="blockquote"><p><span class="emphasis"><em><span class="bold"><b>Next stop... Building your Hello World module from start to finish...</b></span></em></span></p></blockquote></div></div></div><table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr><td align="left"><small><p>Last revised: September 16, 2004 at 03:53:11 GMT</p></small></td><td align="right"><small></small></td></tr></table><hr><div class="spirit-nav"><a accesskey="n" href="boost_python.hello.html"><img src="images/next.png" alt="Next"></a></div></body></html>