printing a sequence...
bolo at coco.ro
Fri Jul 16 12:18:52 CEST 2004
I'm relatively new in using Python and I want to perform a simple job: I
have a list of objects of type A and want to print them to stdout.
def __init__(self, value):
self.value = value
return "value: %d" % self.value
a = [A(10), A(12), A(2)]
I obtain [<__main__.A instance at 0x00767D80>, <__main__.A instance at
0x00768698>, <__main__.A instance at 0x00768350>].
What I want to obtain is [value: 10, value: 12, value: 2].
I know that if I change the __str__ to __repr__ I obtain what I want, but
then I will have these informal strings in debuger also, and I do not want
Can I write somehow the print statement to force calling the A.__str__
More information about the Python-list