[Tutor] static PyObject * or non-static

Rob Benton rob.benton at conwaycorp.net
Thu Sep 16 07:02:02 CEST 2004


Danny Yoo wrote:

>Hi Rob,
>
>
>It's an optimization hack.  *grin*
>See:
>
>    http://docs.python.org/api/countingRefs.html#l2h-68
>
>and
>
>    http://docs.python.org/api/exceptions.html#l2h-26
>
>for another example of this Python/C idiom for handling exceptions.
>
>
>In the original code, since we intend to make 'format' live forever
>anyway, we can omit the code to DECREF it.  So we get two benefits: the
>original program's a little faster, and ends up being shorter to type.
>
>
>Aren't you glad you can program in Python and not in C?  *grin*
>
>
>Hope this helps!
>
>
>
>  
>
Thanks Danny, that explains a lot. It's my fault for dragging this 
thread out such a long time (I forgot I even posted it). One thing I did 
notice in the C API is you can use C++ if you wrap your code inside 
"extern C" statements. Now since I'm more of a C++ guy, it seems like 
using a try catch block would be a lot easier than the gotos or am I 
wrong again :) ?




More information about the Tutor mailing list