###  | # Boost.Python ## Header <boost/python/import.hpp>

## Contents

Introduction
Functions
  `import`
Examples

## Introduction

Exposes a mechanism for importing python modules.

## Functions

### `import`

    object import(str name);

Effects: Imports the module named by `name`.
Returns: An instance of object which holds a reference to the imported module.

## Examples

The following example demonstrates the use of import to access a function in python, and later call it from within C++.

    #include <iostream>
    #include <string>

    using namespace boost::python;

    void print_python_version()
    {
      // Load the sys module.
      object sys = import("sys");

      // Extract the python version.
      std::string version = extract<std::string>(sys.attr("version"));
      std::cout << version << std::endl;
    }

Revised 01 November, 2005

© Copyright Stefan Seefeld 2005.