help with print function in extension
Alex Martelli
aleax at aleax.it
Wed Sep 25 05:26:24 EDT 2002
Eric Hagemann wrote:
> I'm handcrafting an extension in C
>
> If have defined both a str() and a repr() function and when I execute
> either repr(obj), or str(obj) I get what I expect
>
> however if I execute 'print obj' I get the following error
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> SystemError: error return without exception set
>
> although 'print str(obj)' works like I think it should
>
> Am I mistaken in thinking that 'print str(obj)' should be the same as
> 'print obj'
*ALMOST!* In the PyTypeObject struct, there's a tp_print slot
that is used by preference, if non-null, when you print something
and stdout is a real file. What do you have in tp_print for
your type? It's smack in-between tp_dealloc and tp_getattr.
Alex
More information about the Python-list
mailing list