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

2010-02-08 Thread Stefan Seefeld
On 02/08/2010 02:02 AM, Ralf W. Grosse-Kunstleve wrote: 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. Oh, thanks for the correct

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