Re: [C++-sig] Checking for or null PyObject* or PyNone

2010-02-07 Thread Ralf W. Grosse-Kunstleve
> if (obj) ... > > is definitely the right way to do it. Sorry to correct, but it isn't equivalent to "obj is None". if (obj) uses PyObject_IsTrue(); see boost/python/object_operators.hpp line 60. I'll add obj.is_none() and obj.is_not_none() when I get a chance. Ralf __

Re: [C++-sig] Checking for or null PyObject* or PyNone

2010-02-07 Thread Stefan Seefeld
On 02/07/2010 09:32 PM, Jim Bosch wrote: On Sun, 2010-02-07 at 11:47 +0100, Murray Cumming wrote: And what's the correct way to check for PyNone other than if (obj == boost::python::object()) ? I think that's the standard way. I suppose if (obj.ptr() == Py_None) might be faster on

Re: [C++-sig] Checking for or null PyObject* or PyNone

2010-02-07 Thread Jim Bosch
On Sun, 2010-02-07 at 11:47 +0100, Murray Cumming wrote: > Doing this > boost::python::object obj = get_some_object(); > if(obj) > { > //do something > } > seems to check a bool value inside the underlying PyObject, though I > guess that could throw an exception if it doesn't contain a

Re: [C++-sig] ANN: PyBindGen 0.14

2010-02-07 Thread Gustavo Carneiro
On Sun, Feb 7, 2010 at 8:57 PM, Neal Becker wrote: > PyBindGen shows an example wrapping STL containers. What if I need to wrap > my own containers? Is there some generic container machinery? > Yes, there is some generic container machinery, although it currently is duplicating the STL contain

Re: [C++-sig] Executing python code from C++

2010-02-07 Thread Stefan Seefeld
On 02/07/2010 04:51 PM, Murray Cumming wrote: On Sun, 2010-02-07 at 09:51 -0500, Stefan Seefeld wrote: Sorry, I don't understand the question. Can you give an example of what you want to do ? May be you want to "exec" some python code that defines a function, which you then want to extract a

[C++-sig] boost::python and Date/Time values

2010-02-07 Thread Murray Cumming
Is there any easy way to get python Date, Time and DateTime values from boost::python::objects? In C, I'm using PyDateTime_GET_YEAR(), PyDateTime_GET_MONTH(), PyDateTime_GET_DAY(), etc, but it would be nice to use some C++ API for this. -- murr...@murrayc.com www.murrayc.com www.openismus.com __

Re: [C++-sig] Executing python code from C++

2010-02-07 Thread Murray Cumming
On Sun, 2010-02-07 at 09:51 -0500, Stefan Seefeld wrote: > > Sorry, I don't understand the question. Can you give an example of > what > you want to do ? May be you want to "exec" some python code that > defines > a function, which you then want to extract and call later ? > That may look like t

Re: [C++-sig] ANN: PyBindGen 0.14

2010-02-07 Thread Neal Becker
PyBindGen shows an example wrapping STL containers. What if I need to wrap my own containers? Is there some generic container machinery? ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig

[C++-sig] ANN: PyBindGen 0.14

2010-02-07 Thread Gustavo Carneiro
PyBindGen is a Python module that is geared to generating C/C++ code that binds a C/C++ library for Python. It does so without extensive use of either C++ templates or C pre-processor macros. It has modular handling of C/C++ types, and can be easily extended with Python plugins. The generated code

Re: [C++-sig] Executing python code from C++

2010-02-07 Thread Stefan Seefeld
On 02/07/2010 08:29 AM, Murray Cumming wrote: So, I guess I can use boost::python::exec() to call code that defines a Python function. bpl::exec() executes a chunk of Python code, no matter what it contains. But how can I get a boost::python::object for the (callable object of) the functi

Re: [C++-sig] Executing python code from C++

2010-02-07 Thread Murray Cumming
On Sun, 2010-02-07 at 08:03 -0500, Stefan Seefeld wrote: > On 02/07/2010 05:22 AM, Murray Cumming wrote: > > In Glom, to execute arbitrary Python code, I use PyRun_String() to parse > > the Python code, PyDict_GetItemString() and PyObject_Call() to get a > > callable object for that code, and then

Re: [C++-sig] Executing python code from C++

2010-02-07 Thread Stefan Seefeld
On 02/07/2010 05:22 AM, Murray Cumming wrote: In Glom, to execute arbitrary Python code, I use PyRun_String() to parse the Python code, PyDict_GetItemString() and PyObject_Call() to get a callable object for that code, and then PyObject_CallObject() to actually execute the code and get a return v

[C++-sig] Checking for or null PyObject* or PyNone

2010-02-07 Thread Murray Cumming
Doing this boost::python::object obj = get_some_object(); if(obj) { //do something } seems to check a bool value inside the underlying PyObject, though I guess that could throw an exception if it doesn't contain actually contain a bool. Is that right? The reference documentation is not

[C++-sig] Executing python code from C++

2010-02-07 Thread Murray Cumming
In Glom, to execute arbitrary Python code, I use PyRun_String() to parse the Python code, PyDict_GetItemString() and PyObject_Call() to get a callable object for that code, and then PyObject_CallObject() to actually execute the code and get a return value. This was the result of experimentation and