I am creating an Python extension in C, for having a friendly structure and efficient usage on it. So there is a lot of source code for certain heavy operations which should be in C. And a lot of internal fields are referenced.
Now, I was going to do some aesthetic improvements: mainly the tp_repr
and tp_str
slots. Must I do them in C? I am thinking that doing them in Python should be easy, but coding it in C seems to be a nightmare and useless.
I have internal fields like encoded binary strings, a dictionary, and so on. Using Python features seems straightforward:
def repr_func(obj):
return "MyObject(name='%s'.encode('utf-16-be'), id=%d, map=%s)"
% (obj.name.decode("utf-16-be"), obj.id, repr(obj.map))
I know I could do this in C, but it seems cleaner to do it in Python. I do not need performance, those will be used for debugging and testing, so I need them to be useful and clean.
Is there some way to do this without deep changes in the C source?