Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #16641

Re: class print method...

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.020
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'python': 0.08; 'googled': 0.09; 'relevant.': 0.09; 'am,': 0.12; 'classes,': 0.13; 'received:192.168.1.104': 0.16; 'subject:print': 0.16; 'cc:addr :python-list': 0.16; 'advance': 0.17; 'wrote:': 0.18; 'instance': 0.18; 'cc:no real name:2**0': 0.20; 'result.': 0.21; 'header:In- Reply-To:1': 0.22; 'produces': 0.23; 'cc:2**0': 0.24; 'object,': 0.24; 'classes': 0.26; 'tried': 0.27; 'all,': 0.28; 'print': 0.29; 'cc:addr:python.org': 0.29; 'class': 0.29; 'object.': 0.30; 'thanks': 0.31; 'anyone': 0.31; 'objects': 0.32; 'implement': 0.32; "won't": 0.33; 'header:User-Agent:1': 0.33; 'it.': 0.34; 'calling': 0.34; 'anything': 0.34; 'stuck': 0.34; 'issue': 0.35; 'question': 0.36; 'two': 0.37; 'but': 0.37; 'received:192': 0.37; 'skip:_ 10': 0.37; 'could': 0.37; 'using': 0.38; 'created': 0.38; 'data,': 0.39; 'help': 0.39; 'might': 0.40; 'received:192.168': 0.40; 'your': 0.61; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; '02:11': 0.84; 'suresh': 0.91
Date Mon, 05 Dec 2011 02:48:45 -0500
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Thunderbird/3.1.15
MIME-Version 1.0
To Suresh Sharma <ss27051980@gmail.com>
Subject Re: class print method...
References <CALKjt2fen-uZ==A=KJ=-C8JAufU4vmeZQqyW1=3sWR6ajOpXhw@mail.gmail.com>
In-Reply-To <CALKjt2fen-uZ==A=KJ=-C8JAufU4vmeZQqyW1=3sWR6ajOpXhw@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:roxdMJKJ8HZw2Ddty50CHJSORDDpzppS3yfcP4n8SZn P4iYipGaJ8AcRuRIcoJx90BYZPma/1DMCtl8os4fecWYF8JNtU fVU1/3rPpMEhQ5Ewwrx3b/uVUpMTdVY0aqJQ8q0kQejJEP6o4q QYiLxBwKdZ4U0H2Qm8KcIPPzyg5RfOVxtscAYVteU6PIVMa1ke c4uk3sU+wa/9lmIDA/mszosnOmEWnvvoLSHmacNF+5y5LU5IkK aAmIoyBlhWn1zMw45baklqCg1l+wCv3cVZxuBusOSoX/mhhULJ WQUUAVYxvpM4592kO8Lt3+pTHS+x2C0TxdX5OfVtMPTBBbLsQ= =
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To d@davea.name
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3289.1323071369.27778.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1323071369 news.xs4all.nl 6871 [2001:888:2000:d::a6]:46151
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:16641

Show key headers only | View raw


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


Thread

Re: class print method... Dave Angel <d@davea.name> - 2011-12-05 02:48 -0500

csiph-web