[C++-sig] A couple of simple BP V2 questions
Scott A. Smith
ssmith at magnet.fsu.edu
Tue Nov 12 18:38:55 CET 2002
I am biting the bullet and switching my project over to use V2 finally.
Many thanks to everyone working on the BP, the new documentation looks
terrific. I am hoping someone can take the time to answer a couple of
very simple questions to get me started.
1.) In the Hello tutorial, I see that one uses the Python Module name
when creating instances of a class object.
>>> import hello
>>> planet = hello.World()
But in other places, it seems like the module name is not required.
I don't recall ever needing the module name for any exposed classes
from V1. I understand that once planet (above) is made one does not
need hello. to access its members, but is it always true that one
needs it when declaring class objects? What about global functions?
Is there a way to set things so they do not need this?
2.) The tutorial begins dealing with classes, and looks so nice that I
doubt I'll have many problems switching to use V2. But on simpler things
I am at a loss. At the start of my project, before I even get to dealing
with my C++ classes, I have some global variables and functions
declared.
For example,
extern const double PLANCK; (in .hpp)
const double PLANCK = 6.6260755e-34; (in .cpp)
which in BP V1 I exposed using something like
PyModName.add(boost::python::make_ref(PLANCK), "PLANCK");
Now make_ref & PyModName.add are gone, so I took a guess & tried
def("PLANCK", PLANCK, reference_existing_object());
which compiles but doesn't link. How do I exposes a simple constant, not
in any class but globally defined. Can I do it "read-only" as suggested
in the tutorial when explaining class Var where it uses
.def_readonly("name", &Var::name)?
Thanks,
Scott
More information about the Cplusplus-sig
mailing list