From robertsteckroth at gmail.com Sat Dec 1 21:19:48 2012 From: robertsteckroth at gmail.com (Robert Steckroth) Date: Sat, 1 Dec 2012 15:19:48 -0500 Subject: [capi-sig] Fwd: What's up with PyTypeObject and functions? In-Reply-To: References: <50B5D311.6090807@egenix.com> Message-ID: ---------- Forwarded message ---------- From: Robert Steckroth Date: Sat, Dec 1, 2012 at 3:18 PM Subject: Re: [capi-sig] What's up with PyTypeObject and functions? To: "M.-A. Lemburg" Thank you for the response~ I guess I should flesh out implementations before integration into the project. The error checking worked out nicely-> if ( ! PyArg_ParseTupleAndKeywords(args, kwds, "O|OO", kwlist, &s_obj, &align, &padding_list) || !CHECK_TYPE(s_obj, &PySurface_Type) || !CHECK_TYPE(align, &PyString_Type) || !CHECK_TYPE(padding_list, &PyList_Type) ) return NULL; PyErr_Clear(); if ( ! PyArg_ParseTuple(args, "|O", &sd_obj) || (!CHECK_TYPE(sd_obj, &PySurface_Type) && !CHECK_TYPE(sd_obj, &PyDisplay_Type)) ) return NULL; PyErr_Clear(); int CHECK_TYPE(PyObject *s_obj, PyTypeObject *obj_type) { if ( ! s_obj ) return 1; PyObject *obj_str=NULL, *ptype=NULL, *pvalue=NULL, *ptraceback=NULL, *last_error=NULL, *tmp=NULL; if ( ! PyObject_TypeCheck(s_obj, obj_type) ) { obj_str = PyObject_Repr(s_obj); PyErr_Fetch(&ptype, &pvalue, &ptraceback); if ( pvalue ) { tmp = PyObject_Str(pvalue); last_error = PyString_FromFormat("%s or", PyString_AsString(tmp)); } else { last_error=PyString_FromString(""); } PyErr_Format(PyExc_TypeError, "%s [ %s ] object needs to be of type [ %s ]", PyString_AsString(last_error), PyString_AsString(obj_str), obj_type->tp_name ); Py_DECREF(obj_str); Py_DECREF(last_error); Py_XDECREF(tmp); Py_XDECREF(pvalue); Py_XDECREF(ptype); Py_XDECREF(ptraceback); return NULL; } return 1; } On Wed, Nov 28, 2012 at 4:02 AM, M.-A. Lemburg wrote: > On 28.11.2012 04:01, Robert Steckroth wrote: > > Hey Gang, why is the below snippet for error checking not working? I > wan't > > to be able to pass in different PyTypeObjects > > to the CHECK_TYPE function and check an object for that type. > > It works fine when I insert put &PyString_Type directly into > > the function like so --> > > if ( ! PyObject_TypeCheck(s_obj, &PyString_type) ) > > However, the CHECK_TYPE function will return -1 if I pass the > PyTypeObject > > in, like at the bottom of this message. > > Why does PyObject_TypeCheck not work if PyTypeObject is first passed > into a > > function? > > > > > > int CHECK_TYPE(PyObject *s_obj, PyTypeObject obj_type) { > > You need *obj_type here, since you need the pointer to the object, not > the object itself. > > > if ( ! s_obj ) > > return 1; > > > > if ( ! PyObject_TypeCheck(s_obj, &obj_type) ) { > > This needs to be obj_type. > > Your code will pass in the address of > the PyTypeObject on the stack, which will not match any of the > type objects in the Python type system. > > > PyErr_Format(PyExc_TypeError, "[ %s ] object needs to be of > > type [ %s ]\n\nUsage: %s", PyString_AsString(PyObject_Repr(s_obj)), > > obj_type.tp_name, obj_type.tp_doc ); > > This code leaks memory since the representation object is not freed. > > > return -1; } > > > > return 1; > > > > } > > > > if ( !CHECK_TYPE(align, PyString_Type) ) return NULL; > > This needs to the &PyString_Type > > -- > Marc-Andre Lemburg > eGenix.com > > Professional Python Services directly from the Source (#1, Nov 28 2012) > >>> Python Projects, Consulting and Support ... http://www.egenix.com/ > >>> mxODBC.Zope/Plone.Database.Adapter ... http://zope.egenix.com/ > >>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/ > ________________________________________________________________________ > > ::: Try our new mxODBC.Connect Python Database Interface for free ! :::: > > eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 > D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg > Registered at Amtsgericht Duesseldorf: HRB 46611 > http://www.egenix.com/company/contact/ > -- Bust0ut, Surgemcgee: Systems Engineer --- surgemcgee.com Django_Teamplate3d -- Bust0ut, Surgemcgee: Systems Engineer --- surgemcgee.com Django_Teamplate3d From robertsteckroth at gmail.com Sat Dec 1 21:07:37 2012 From: robertsteckroth at gmail.com (Robert Steckroth) Date: Sat, 1 Dec 2012 15:07:37 -0500 Subject: [capi-sig] A new Python module! Message-ID: Pygui is underway! It is a Python SDL Wrapper for quick application development. I have posted a short video to Youtube for proof of concept. The goal of PyGui is to maintain a safe framework environment for stable and graphical application creation. It will use a macro event system attached python callbacks for execution of code or binary/script files. There will be zero memory concerns which will allow software developers to finish small projects on there own. It aims to be HTML like in design with many of its' features. Feel free to contact me with any questions as it needs much support. Robert Steckroth. Direct link -> http://www.youtube.com/watch?v=ha13zg_LESY&feature=youtu.be Note: Video has no audio. -- Bust0ut, Surgemcgee: Systems Engineer --- surgemcgee.com Django_Teamplate3d From philip at semanchuk.com Sat Dec 1 21:49:18 2012 From: philip at semanchuk.com (Philip Semanchuk) Date: Sat, 1 Dec 2012 15:49:18 -0500 Subject: [capi-sig] A new Python module! In-Reply-To: References: Message-ID: <72B7C275-766A-40C5-8CFB-3358B0DB1578@semanchuk.com> On Dec 1, 2012, at 3:07 PM, Robert Steckroth wrote: > Pygui is underway! It is a Python SDL Wrapper for quick application > development. I have posted a short video to Youtube for proof of concept. > The goal of PyGui is to maintain a safe framework environment for stable > and graphical application creation. It will use a macro event system > attached python callbacks for execution of code or binary/script files. > There will be zero memory concerns which will allow software developers to > finish small projects on there own. It aims to be HTML like in design with > many of its' features. Feel free to contact me with any questions as it > needs much support. Hi Robert, Is this different from Greg Ewing's PyGui? http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ Cheers Philip From robertsteckroth at gmail.com Sun Dec 2 19:55:15 2012 From: robertsteckroth at gmail.com (Robert Steckroth) Date: Sun, 2 Dec 2012 13:55:15 -0500 Subject: [capi-sig] How to retrieve an objects method or attribute doc string? Message-ID: I have an Python Object with a type PySurface_Type. The Object has a method called Properties like so -> {"Properties", (PyCFunction)Surface_set_properties, METH_VARARGS| METH_KEYWORDS, "Set the surface properties as a list of integers or keywords, e.g. set_properties(x=[int][PyList[int, ...], y=int, width=int, height=int). Note: the Python list must be the first argument or x=PyList[int, ...] "}, How can I get the doc string from this method? I would like to print this in an error message. Is it possible to get the Member doc string as well? -- Bust0ut, Surgemcgee: Systems Engineer --- surgemcgee.com Django_Teamplate3d From hniksic at xemacs.org Mon Dec 3 21:41:51 2012 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Mon, 03 Dec 2012 21:41:51 +0100 Subject: [capi-sig] How to retrieve an objects method or attribute doc string? In-Reply-To: (Robert Steckroth's message of "Sun, 2 Dec 2012 13:55:15 -0500") References: Message-ID: <87ip8ina0g.fsf@xemacs.org> Robert Steckroth writes: > I have an Python Object with a type PySurface_Type. The Object > has a method called Properties like so -> > > {"Properties", (PyCFunction)Surface_set_properties, METH_VARARGS| > METH_KEYWORDS, > "Set the surface properties as a list of integers or keywords, e.g. > set_properties(x=[int][PyList[int, ...], y=int, width=int, height=int). > Note: the Python list must be the first argument or x=PyList[int, ...] > "}, > > How can I get the doc string from this method? I would like to print this > in an error message. The docstring is available as the __doc__ attribute of the surface.Properties object ("surface" being the Python name of PySurface_Type). In Python one would access it as surface.Properties.__doc__, which would translate to Python/C as: const char *surface_props_doc_string() { PyObject *propdeco, *doc; const char *doc_str; propdeco = PyObject_GetAttrString((PyObject *) PySurface_Type, "Properties"); if (!propdeco) return NULL; doc = PyObject_GetAttrString(propdeco, "__doc__"); Py_DECREF(propdeco); if (!doc) return NULL; doc_str = PyString_AsString(doc); Py_DECREF(doc); return doc_str; } From robertsteckroth at gmail.com Wed Dec 5 20:14:43 2012 From: robertsteckroth at gmail.com (Robert Steckroth) Date: Wed, 5 Dec 2012 14:14:43 -0500 Subject: [capi-sig] Does PyObject_SetAttrString am PyArg_Parse steal an object reference? Message-ID: In the below example, is there an extra reference to the align object when the Py_RETURN_NONE IS hit? Also, why do I have to Py_INCREF(s_obj)? If I do not, I end up with crashes. Is this a bug? PyObject *s_obj=NULL, *align=NULL; if ( ! PyArg_ParseTupleAndKeywords(args, kwds, "|OO", kwlist, &s_obj, &align) ) return NULL; if ( s_obj ) Py_XINCREF(s_obj); if ( align ) { Py_XINCREF(align); PyObject_SetAttrString(s_obj, "align", align); } Py_RETURN_NONE; } -- Bust0ut, Surgemcgee: Systems Engineer --- surgemcgee.com Django_Teamplate3d From hniksic at xemacs.org Thu Dec 6 08:42:20 2012 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Thu, 06 Dec 2012 08:42:20 +0100 Subject: [capi-sig] Does PyObject_SetAttrString am PyArg_Parse steal an object reference? In-Reply-To: (Robert Steckroth's message of "Wed, 5 Dec 2012 14:14:43 -0500") References: Message-ID: <87ehj3mxsz.fsf@xemacs.org> Robert Steckroth writes: > In the below example, is there an extra reference to the align object > when the Py_RETURN_NONE IS hit? There is. Since PyObject_SetAttrString doesn't steal the reference count to its argument, the Py_XINCREF is unnecessary. Also, I'd use Py_INCREF there, since you already aren't entering the if-clause if align is NULL. > Also, why do I have to Py_INCREF(s_obj)? You don't. PyArg_ParseTupleAndKeywords doesn't increase reference count of its arguments, and neither should the code calling it -- it is the responsibility of the caller to provide arguments that it either owns or are globally available (Py_None, type objects). > If I do not, I end up with crashes. Is this a bug? It's most likely a bug somewhere else in your code or an extension you're using that gets hidden by the extra incref. This can sometimes happen in Python/C; the correct solution is to remove the extraneous incref and carefully inspect the rest of your code for incorrect reference count handling. From robertsteckroth at gmail.com Tue Dec 11 20:40:04 2012 From: robertsteckroth at gmail.com (Robert Steckroth) Date: Tue, 11 Dec 2012 14:40:04 -0500 Subject: [capi-sig] Open sourced the Python PySurface Module! Message-ID: Hello Gang, I have open-sourced the PySurface module and started the documentation. I know there is some novel ideas in there for anyone in this field, so check it out. I can't wait to slap this one into my resume! Also, any constructive criticism is welcome as this project a large cookie. I have not uploaded the Docs to ReadTheDocs.org yet, so you can scope out my in-house design and get the repository here --> www.surgemcgee.com Robert Steckroth -- Bust0ut, Surgemcgee: Systems Engineer --- surgemcgee.com Django_Teamplate3d From hniksic at xemacs.org Wed Dec 12 00:08:58 2012 From: hniksic at xemacs.org (Hrvoje Niksic) Date: Wed, 12 Dec 2012 00:08:58 +0100 Subject: [capi-sig] Open sourced the Python PySurface Module! In-Reply-To: (Robert Steckroth's message of "Tue, 11 Dec 2012 14:40:04 -0500") References: Message-ID: <874njsmbjp.fsf@xemacs.org> Robert Steckroth writes: > Hello Gang, I have open-sourced the PySurface module and started the > documentation. I know there is some novel ideas in there for anyone in > this field, so check it out. I can't wait to slap this one into my > resume! Also, any constructive criticism is welcome as this project a > large cookie. Congratulations! However, the python mailing list/newsgroup might be a better place for the announcement, as this list has a fairly narrow audience. You might also want to put up the project on PyPI, so it gets some attention. From robertsteckroth at gmail.com Wed Dec 12 19:45:09 2012 From: robertsteckroth at gmail.com (Robert Steckroth) Date: Wed, 12 Dec 2012 13:45:09 -0500 Subject: [capi-sig] How do I get the Objects to clean up after a python script exits? Message-ID: When I test my module in the interpreter it automatically cleans up any created objects. This is a very nice feature for my module and I would like to use it. How do I go about getting my scripts to send an exit cleanup single? -- Bust0ut, Surgemcgee: Systems Engineer --- surgemcgee.com Django_Teamplate3d From robertsteckroth at gmail.com Thu Dec 13 17:21:16 2012 From: robertsteckroth at gmail.com (Robert Steckroth) Date: Thu, 13 Dec 2012 11:21:16 -0500 Subject: [capi-sig] Does Py_False or Py_True need de-referencing if used in a PyObject_Compare? Message-ID: Does the below statement have a memory leak? if ( PyObject_Compare(update_var, Py_False) Do I need to assign the Py_False first and DECREF it, or is the above snippet ok alone. -- Bust0ut, Surgemcgee: Systems Engineer --- surgemcgee.com Django_Teamplate3d From robertsteckroth at gmail.com Thu Dec 13 17:57:24 2012 From: robertsteckroth at gmail.com (Robert Steckroth) Date: Thu, 13 Dec 2012 11:57:24 -0500 Subject: [capi-sig] Does Py_False or Py_True need de-referencing if used in a PyObject_Compare? In-Reply-To: References: Message-ID: Well, from what I have gathered, the reference count does not need to be maintain as far as PyBool objects go. It seem to be fine even if the object is set from a argument. Hmmm... On Thu, Dec 13, 2012 at 11:21 AM, Robert Steckroth < robertsteckroth at gmail.com> wrote: > Does the below statement have a memory leak? > > if ( PyObject_Compare(update_var, Py_False) > > Do I need to assign the Py_False first and DECREF it, or is the above > snippet ok alone. > > -- > Bust0ut, Surgemcgee: Systems Engineer --- > surgemcgee.com > Django_Teamplate3d > -- Bust0ut, Surgemcgee: Systems Engineer --- surgemcgee.com Django_Teamplate3d From python_capi at behnel.de Sat Dec 15 15:31:50 2012 From: python_capi at behnel.de (Stefan Behnel) Date: Sat, 15 Dec 2012 15:31:50 +0100 Subject: [capi-sig] How do I get the Objects to clean up after a python script exits? In-Reply-To: References: Message-ID: <50CC89D6.7070202@behnel.de> Robert Steckroth, 12.12.2012 19:45: > When I test my module in the interpreter it automatically cleans up any > created objects. This is a very nice feature > for my module and I would like to use it. How do I go about getting > my scripts to send an exit cleanup single? Depends on exactly what you are trying to achieve, but you might want to look at the atexit module. Py3 additionally has the PyModuleDef setup which allows you to clean up module globals at exactly the right time on interpreter tear down. It basically implements garbage collection for modules. (Shameless hint: Cython cleans up global variables for you automatically and chooses the right way to do so based on the capabilities of the current runtime.) Stefan From python_capi at behnel.de Sat Dec 15 15:33:27 2012 From: python_capi at behnel.de (Stefan Behnel) Date: Sat, 15 Dec 2012 15:33:27 +0100 Subject: [capi-sig] Does Py_False or Py_True need de-referencing if used in a PyObject_Compare? In-Reply-To: References: Message-ID: <50CC8A37.20604@behnel.de> Robert Steckroth, 13.12.2012 17:57: > Well, from what I have gathered, the reference count does not need to be > maintain as far as PyBool objects go. They are like any other object, i.e. they need reference counting. > It seem to be fine even if the object is set from a argument. Hmmm... That's a different case. As long as you are sure that someone (better you) owns a reference to the object that you pass as argument, you don't need to increase its refcount just for the call. That's easy to get wrong, though. >> Does the below statement have a memory leak? >> >> if ( PyObject_Compare(update_var, Py_False) Why should it? >> Do I need to assign the Py_False first and DECREF it, or is the above >> snippet ok alone. I keep being surprised by what some people take their fun in programming from. Good to see that you're getting actual functionality done regardless. Stefan From ideasman42 at gmail.com Sat Dec 15 15:46:50 2012 From: ideasman42 at gmail.com (Campbell Barton) Date: Sun, 16 Dec 2012 01:46:50 +1100 Subject: [capi-sig] Does Py_False or Py_True need de-referencing if used in a PyObject_Compare? In-Reply-To: References: Message-ID: On Fri, Dec 14, 2012 at 3:21 AM, Robert Steckroth wrote: > Does the below statement have a memory leak? > > if ( PyObject_Compare(update_var, Py_False) > > Do I need to assign the Py_False first and DECREF it, or is the above > snippet ok alone. The python api docs will often say if they use/steal references. If your not sure you could just printf("%d\n", Py_REFCNT(Py_False)); before and after calling. From stefan_ml at behnel.de Sat Dec 15 15:06:39 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 15 Dec 2012 15:06:39 +0100 Subject: [capi-sig] Does Py_False or Py_True need de-referencing if used in a PyObject_Compare? In-Reply-To: References: Message-ID: <50CC83EF.6030508@behnel.de> Robert Steckroth, 13.12.2012 17:57: > Well, from what I have gathered, the reference count does not need to be > maintain as far as PyBool objects go. They are like any other object, i.e. they need reference counting. > It seem to be fine even if the object is set from a argument. Hmmm... That's a different case. As long as you are sure that someone (better you) owns a reference to the object that you pass as argument, you don't need to increase its refcount just for the call. That's easy to get wrong, though. >> Does the below statement have a memory leak? >> >> if ( PyObject_Compare(update_var, Py_False) Why should it? >> Do I need to assign the Py_False first and DECREF it, or is the above >> snippet ok alone. I keep being surprised by what some people take their fun in programming from. Good to see that you're getting actual functionality done regardless. Stefan From stefan_ml at behnel.de Sat Dec 15 15:08:46 2012 From: stefan_ml at behnel.de (Stefan Behnel) Date: Sat, 15 Dec 2012 15:08:46 +0100 Subject: [capi-sig] How do I get the Objects to clean up after a python script exits? In-Reply-To: References: Message-ID: <50CC846E.2010501@behnel.de> Robert Steckroth, 12.12.2012 19:45: > When I test my module in the interpreter it automatically cleans up any > created objects. This is a very nice feature > for my module and I would like to use it. How do I go about getting > my scripts to send an exit cleanup single? Depends on what you are trying to achieve, but you might want to look at the atexit module. (Shameless hint: Cython cleans up global variables for you automatically.) Stefan From ideasman42 at gmail.com Sun Dec 16 17:04:59 2012 From: ideasman42 at gmail.com (Campbell Barton) Date: Mon, 17 Dec 2012 03:04:59 +1100 Subject: [capi-sig] How do I get the Objects to clean up after a python script exits? In-Reply-To: References: Message-ID: On Thu, Dec 13, 2012 at 5:45 AM, Robert Steckroth wrote: > When I test my module in the interpreter it automatically cleans up any > created objects. This is a very nice feature > for my module and I would like to use it. How do I go about getting > my scripts to send an exit cleanup single? > > -- > Bust0ut, Surgemcgee: Systems Engineer --- > surgemcgee.com > Django_Teamplate3d > _______________________________________________ > capi-sig mailing list > capi-sig at python.org > http://mail.python.org/mailman/listinfo/capi-sig Heres an example of using atexit from C/Python api. (py3.x) https://svn.blender.org/svnroot/bf-blender/trunk/blender/source/blender/python/intern/bpy_interface_atexit.c -- - Campbell From gjcarneiro at gmail.com Mon Dec 17 12:23:59 2012 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Mon, 17 Dec 2012 11:23:59 +0000 Subject: [capi-sig] Does Py_False or Py_True need de-referencing if used in a PyObject_Compare? In-Reply-To: References: Message-ID: On Thu, Dec 13, 2012 at 4:21 PM, Robert Steckroth wrote: > Does the below statement have a memory leak? > > if ( PyObject_Compare(update_var, Py_False) > > Do I need to assign the Py_False first and DECREF it, or is the above > snippet ok alone. > It's safe, but note that it is more correct to use PyObject_IsTrue: there are more values that can be considered true or false, besides python's True and False objects. if (!PyObject_IsTrue(update_var)) { ... } -- Gustavo J. A. M. Carneiro "The universe is always one step beyond logic." -- Frank Herbert From ideasman42 at gmail.com Mon Dec 17 14:59:17 2012 From: ideasman42 at gmail.com (Campbell Barton) Date: Tue, 18 Dec 2012 00:59:17 +1100 Subject: [capi-sig] Does Py_False or Py_True need de-referencing if used in a PyObject_Compare? In-Reply-To: References: Message-ID: 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 wrote: > PyObject_IsTrue( -- - Campbell From gjcarneiro at gmail.com Mon Dec 17 17:45:37 2012 From: gjcarneiro at gmail.com (Gustavo Carneiro) Date: Mon, 17 Dec 2012 16:45:37 +0000 Subject: [capi-sig] Does Py_False or Py_True need de-referencing if used in a PyObject_Compare? In-Reply-To: References: Message-ID: 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 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 > 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 From robertsteckroth at gmail.com Mon Dec 17 18:30:49 2012 From: robertsteckroth at gmail.com (Robert Steckroth) Date: Mon, 17 Dec 2012 12:30:49 -0500 Subject: [capi-sig] Looking for an opportunity to work with the Python CAPI Message-ID: I apologize if this post is a little spamy, but if there are any professionals who can point me towards a starting position in regards to this industry, I would be grateful. If not, what type of companies use the Python CAPI? -- Bust0ut, Surgemcgee: Systems Engineer --- surgemcgee.com Django_Teamplate3d From ideasman42 at gmail.com Tue Dec 18 05:48:53 2012 From: ideasman42 at gmail.com (Campbell Barton) Date: Tue, 18 Dec 2012 15:48:53 +1100 Subject: [capi-sig] Does Py_False or Py_True need de-referencing if used in a PyObject_Compare? In-Reply-To: References: Message-ID: It depends, sometimes you wont want to allow this for attribute assignment since it can be misleading. eg: foo.bar = [] On Tue, Dec 18, 2012 at 3:45 AM, Gustavo Carneiro wrote: > 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 > 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 >> 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 -- - Campbell