maybe this is a print odds

P

pipehappy

I come this code:

Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information..... def __str__(self):
.... return "He"
....
hes = [He(),He(),He()]
print hes
[<__main__.He object at 0x00BE92D0>, <__main__.He object at
0x00BE9370>, <__main
__.He object at 0x00BE93B0>] # I expect output: [He,He,He]

Do anyone know trick to overcome this or python has some proposal to
extend print that can do iterately print? I just want to get the way of
print which I my guess. Thanks a lot!
 
P

Peter Otten

pipehappy said:
I come this code:

Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit
(Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.... def __str__(self):
... return "He"
...
hes = [He(),He(),He()]
print hes
[<__main__.He object at 0x00BE92D0>, <__main__.He object at
0x00BE9370>, <__main
__.He object at 0x00BE93B0>] # I expect output: [He,He,He]

Do anyone know trick to overcome this or python has some proposal to
extend print that can do iterately print? I just want to get the way of
print which I my guess. Thanks a lot!

Lists print their items via repr(), not str():
.... def __str__(self):
.... return "That's a bit early, don't you think?"
.... def __repr__(self):
.... return "Ho"
....
print [Ho()] * 3 [Ho, Ho, Ho]
print Ho()
That's a bit early, don't you think?

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top