Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/doc/v2/import.html @ 45

Last change on this file since 45 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.5 KB
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
3<!-- Copyright David Abrahams 2006. Distributed under the Boost -->
4<!-- Software License, Version 1.0. (See accompanying -->
5<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
6<html>
7  <head>
8    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
9    <link rel="stylesheet" type="text/css" href="../boost.css">
10
11    <title>Boost.Python - &lt;boost/python/import.hpp&gt;</title>
12  </head>
13
14  <body>
15    <table border="0" cellpadding="7" cellspacing="0" width="100%" summary=
16    "header">
17      <tr>
18        <td valign="top" width="300">
19          <h3><a href="../../../../index.htm"><img height="86" width="277"
20          alt="C++ Boost" src="../../../../boost.png" border="0"></a></h3>
21        </td>
22
23        <td valign="top">
24          <h1 align="center"><a href="../index.html">Boost.Python</a></h1>
25
26          <h2 align="center">Header &lt;boost/python/import.hpp&gt;</h2>
27        </td>
28      </tr>
29    </table>
30    <hr>
31
32    <h2>Contents</h2>
33
34    <dl class="page-index">
35      <dt><a href="#introduction">Introduction</a></dt>
36
37      <dt><a href="#functions">Functions</a></dt>
38
39      <dd>
40        <dl class="page-index">
41          <dt><a href="#import-spec"><code>import</code></a></dt>
42        </dl>
43      </dd>
44      <dt><a href="#examples">Examples</a></dt>
45    </dl>
46    <hr>
47
48    <h2><a name="introduction"></a>Introduction</h2>
49
50    <p>Exposes a mechanism for importing python modules.</p>
51
52    <h2><a name="functions"></a>Functions</h2>
53
54    <h3><a name="import-spec"></a><code>import</code></h3>
55    <pre>
56object import(str name);
57    </pre>
58    <dl class="function-semantics">
59      <dt><b>Effects:</b> Imports the module named by <code>name</code>.</dt>
60      <dt><b>Returns:</b> An instance of <a href="object.html#object-spec">object</a> 
61       which holds a reference to the imported module.</dt>
62    </dl>
63
64    <h2><a name="examples"></a>Examples</h2>
65
66    <para>The following example demonstrates the use of <function>import</function>
67      to access a function in python, and later call it from within C++.</para>
68
69<pre>
70#include &lt;iostream&gt;
71#include &lt;string&gt;
72
73using namespace boost::python;
74
75void print_python_version()
76{
77  // Load the sys module.
78  object sys = import("sys");
79
80  // Extract the python version.
81  std::string version = extract&lt;std::string&gt;(sys.attr("version"));
82  std::cout &lt;&lt; version &lt;&lt; std::endl;
83}
84</pre>
85    <p>Revised 01 November, 2005</p>
86
87    <p><i>&copy; Copyright Stefan Seefeld 2005.</i></p>
88  </body>
89</html>
90
Note: See TracBrowser for help on using the repository browser.