[C++-sig] Re: C++-sig digest, Vol 1 #559 - 16 msgs

Zhang Le ejoy at 163.com
Thu Jun 5 09:22:21 CEST 2003


> Date: Wed, 04 Jun 2003 07:54:01 -0800
> From: Nicodemus <nicodemus at globalite.com.br>
> To: c++-sig at python.org
> Subject: Re: [C++-sig] wrap global variable (def not work)
> Reply-To: c++-sig at python.org
> Try this:
> 
> int verbose = 1;
> int get_verbose() { return verbose; }
> BOOST_PYTHON_MODULE(foo)
> {
>     scope().attr("verbose") = verbose;
>     def("get_verbose", &get_verbose);
> }
> 
> Ie, changes in a global variable won't be seen in C++, so this
> technique works only for constants. If you *really* need to be able to
> change the global variable from Python, you will have to create
> accessor functions and use these. That's not Boost.Python fault
> really, is just that in Python there's no way to know when a
> module-variable is *rebound* (note, not *changed*).


More information about the Cplusplus-sig mailing list