Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.01; 'help?': 0.03; 'wed,': 0.03; 'sys': 0.05; 'variable,': 0.07; '[],': 0.09; '__name__': 0.09; 'append': 0.09; 'callable': 0.09; 'object.': 0.09; 'tuple': 0.09; 'pm,': 0.10; 'wrote:': 0.14; '"))': 0.16; '"__main__":': 0.16; '(0,': 0.16; '(self):': 0.16; 'object)': 0.16; 'subject:Objects': 0.16; 'subject:PLEASE': 0.16; '\xa0def': 0.16; '\xa0for': 0.16; '\xa0print': 0.16; '\xa0while': 0.16; 'object,': 0.19; 'header:In-Reply-To:1': 0.21; 'trying': 0.23; 'replacing': 0.23; 'skip:\xa0 40': 0.23; 'wrong?': 0.23; 'code': 0.24; 'index': 0.25; 'function': 0.25; 'specified': 0.26; 'url:mailman': 0.26; 'object': 0.26; 'message-id:@mail.gmail.com': 0.28; '(the': 0.28; 'import': 0.29; 'subject:HELP': 0.29; 'class': 0.29; 'url:listinfo': 0.30; 'get.': 0.30; 'typeerror:': 0.30; 'supposed': 0.31; 'print': 0.31; 'done': 0.32; 'to:addr:python- list': 0.33; 'list': 0.33; 'list.': 0.33; 'follows:': 0.34; 'here,': 0.35; '8bit%:5': 0.36; 'too.': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.37; 'two': 0.37; 'url:python': 0.38; 'url:org': 0.38; 'but': 0.38; 'subject:: ': 0.38; '8bit%:6': 0.39; 'received:209': 0.39; 'list,': 0.39; 'to:addr:python.org': 0.39; 'getting': 0.40; 'really': 0.40; 'format': 0.40; 'almost': 0.60; 'subject:, ': 0.60; 'below:': 0.79; 'dogs': 0.84; 'everything,': 0.84; 'everything.': 0.84; 'subject:Methods': 0.84; 'things:': 0.93 MIME-Version: 1.0 In-Reply-To: References: Date: Wed, 8 Jun 2011 13:34:49 -0700 Subject: Re: Of Functions, Objects, and Methods-I NEED HELP PLEASE From: Benjamin Kaplan To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Junkmail-Status: score=10/49, host=mpv1.tis.cwru.edu X-Junkmail-Signature-Raw: score=unknown, refid=str=0001.0A020209.4DEFDCEB.003C,ss=1,fgs=0, ip=209.85.210.54, so=2010-12-23 16:51:53, dmn=2009-09-10 00:05:08, mode=single engine X-Junkmail-IWF: false X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 72 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1307565299 news.xs4all.nl 49175 [::ffff:82.94.164.166]:35524 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7258 On Wed, Jun 8, 2011 at 1:09 PM, Cathy James wrote: > I am almost there, but I need a little help: > > I would like to > > a) print my dogs in the format =A0index. name: breed as follows: > > 0. Mimi:Poodle > 1.Sunny: Beagle > 2. Bunny: German Shepard > I am getting > > (0, ('Mimi', 'Poodle')) . Mimi : Poodle instead-what have I done wrong? > > b) I would like to append to my list, but my line dogs.dogAppend() is > giving a TypeError: > > for i in enumerate (self.dogAppend()): > TypeError: 'list' object is not callable > > Any help? > > #MY CODE BELOW: > > import sys > class Dog(): > =A0 =A0def __init__(self, name, breed): > =A0 =A0 =A0 =A0self.name =3D name > =A0 =A0 =A0 =A0self.breed =3D breed > > =A0 =A0def dogAppend(self): > =A0 =A0 =A0 =A0self.dogAppend =3D [] > =A0 =A0 =A0 =A0self.dogAppend.append((self.name,self.breed)) > =A0 =A0 =A0 =A0return self.dogAppend > In Python, everything is an object. And when we say everything, we really do mean everything. A function is an object too. So when you do self.dogAppend =3D [], you're replacing self.dogAppend (the function object) with a list. > > =A0 =A0def display (self): > =A0 =A0 =A0 =A0for i in enumerate (self.dogAppend()): I don't know what you're trying to do here, because this makes no sense. dogAppend is going to return a list of a single object, so it's going to be 0 every time. And enumerate returns two things: the index and the object. Since you only specified one variable, you get the tuple of (index, object) which is what you're seeing. You're supposed to do : for i, dog in enumerate(a_list_of_all_the_dogs) : =A0 =A0 =A0 =A0 =A0 =A0print (i,".", =A0dog.name, ": " + dog.breed) for what you're trying to get. > > if __name__ =3D=3D "__main__": > =A0 =A0dogs =3D Dog(name=3Dinput (" Enter Dog Name: "), breed=3Dinput ("E= nter > Dog Breed: ")) > =A0 =A0while not dogs: > =A0 =A0 =A0 =A0print("Goodbye!!") > =A0 =A0 =A0 =A0sys.exit() > =A0 =A0else: > =A0 =A0 =A0 =A0#dogs.dogAppend() > =A0 =A0 =A0 =A0dogs.display() > -- > http://mail.python.org/mailman/listinfo/python-list >