[capi-sig] Does Py_False or Py_True need de-referencing if used in a PyObject_Compare?

Gustavo Carneiro gjcarneiro at gmail.com
Mon Dec 17 17:45:37 CET 2012


You are not wrong.  On the other hand, I often depend on the fact that an
empty list or dictionary is false, and true if not empty.  It is quite
convenient, and I find it reasonably logical.

On Mon, Dec 17, 2012 at 1:59 PM, Campbell Barton <ideasman42 at gmail.com>wrote:

> Take care using PyObject_IsTrue since it will accept many PyObject's
> (floats, lists, dicts etc), if you want to be strict with checking
> your input its not always so good.
> Instead you can use PyLong_AsLong() this works for True/False and any int
> type.
>
> eg:
>         int param = PyLong_AsLong(value);
>         if (param == -1 && PyErr_Occurred()) {
>           .... error out ...
>         }
>         ... check the int now ...
>
> On Mon, Dec 17, 2012 at 10:23 PM, Gustavo Carneiro <gjcarneiro at gmail.com>
> wrote:
> > PyObject_IsTrue(
>
>
>
> --
> - Campbell
> _______________________________________________
> capi-sig mailing list
> capi-sig at python.org
> http://mail.python.org/mailman/listinfo/capi-sig
>



-- 
Gustavo J. A. M. Carneiro
"The universe is always one step beyond logic." -- Frank Herbert


More information about the capi-sig mailing list