diff --git a/doc/v2/scope.html b/doc/v2/scope.html index 17450645..93a9b100 100644 --- a/doc/v2/scope.html +++ b/doc/v2/scope.html @@ -64,11 +64,16 @@

Class scope

-

The scope class has an associated global Python object - which controls the Python namespace in which new extension classes and - wrapped functions will be defined as attributes. Default-constructing a - new scope object binds that object to the associated Python - object. Constructing a is associated with , and

+

The scope class has an associated global Python + object which controls the Python namespace in which new extension + classes and wrapped functions will be defined as + attributes. Default-constructing a new scope object + binds it to the associated global Python object. Constructing a + scope object with an argument changes the associated + global Python object to the one held by the argument, until the + lifetime of the scope object ends, at which time the + associated global Python object reverts to what it was before the + scope object was constructed.

Class scope synopsis

@@ -121,15 +126,22 @@ struct X { void f(); - struct Y { int g() { return 0; } }; + struct Y { int g() { return 42; } }; }; BOOST_PYTHON_MODULE(nested) { + // add some constants to the current (module) scope + scope().attr("yes") = 1; + scope().attr("no") = 0; + + // Change the current scope scope outer = class_<X>("X") .def("f", &X::f) ; + + // Define a class Y in the current scope, X class_<Y>("Y") .def("g", &Y::g) ; @@ -138,12 +150,14 @@ BOOST_PYTHON_MODULE(nested) Interactive Python:
 >>> import nested
+>>> nested.yes
+1
 >>> y = nested.X.Y()
 >>> y.g()
-0
+42
 
-

Revised 03 October, 2002

+

Revised 09 October, 2002

© Copyright Dave Abrahams 2002. All Rights