Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #16641
| Date | 2011-12-05 02:48 -0500 |
|---|---|
| From | Dave Angel <d@davea.name> |
| Subject | Re: class print method... |
| References | <CALKjt2fen-uZ==A=KJ=-C8JAufU4vmeZQqyW1=3sWR6ajOpXhw@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3289.1323071369.27778.python-list@python.org> (permalink) |
On 12/05/2011 02:11 AM, Suresh Sharma wrote: > Hello All, > I am new to python and i have stuck up on a particular issue with classes, > i understand this might be a very dumb question but please help me out. > > I have created two classes and whenever i try to print the objects i get > this message but not the data, __main__.cards instance at ****(memory > location) i even tried using __str__ but calling it also produces the same > result. Can anyone please help me how to get my objects printed. I googled > a lot but could not find anything relevant. > > thanks in advance > > regards > suresh > You were close, but you have it backward. You don't call __str__() to print an object, you implement __str__() in your object. If you write a class without also writing __str__(), then print won't know what to do with it. -- DaveA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: class print method... Dave Angel <d@davea.name> - 2011-12-05 02:48 -0500
csiph-web