Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7258
| 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 | <bsk16@case.edu> |
| 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 | <BANLkTimNb3r31sQOZ8Go8qbppg9-T6HsBg@mail.gmail.com> |
| References | <BANLkTimNb3r31sQOZ8Go8qbppg9-T6HsBg@mail.gmail.com> |
| Date | Wed, 8 Jun 2011 13:34:49 -0700 |
| Subject | Re: Of Functions, Objects, and Methods-I NEED HELP PLEASE |
| From | Benjamin Kaplan <benjamin.kaplan@case.edu> |
| 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 <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.34.1307565299.11593.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
On Wed, Jun 8, 2011 at 1:09 PM, Cathy James <nambo4jb@gmail.com> wrote:
> I am almost there, but I need a little help:
>
> I would like to
>
> a) print my dogs in the format index. 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():
> def __init__(self, name, breed):
> self.name = name
> self.breed = breed
>
> def dogAppend(self):
> self.dogAppend = []
> self.dogAppend.append((self.name,self.breed))
> return 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 = [], you're replacing self.dogAppend (the function
object) with a list.
>
> def display (self):
> for 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) :
print (i,".", dog.name, ": " + dog.breed)
for what you're trying to get.
>
> if __name__ == "__main__":
> dogs = Dog(name=input (" Enter Dog Name: "), breed=input ("Enter
> Dog Breed: "))
> while not dogs:
> print("Goodbye!!")
> sys.exit()
> else:
> #dogs.dogAppend()
> dogs.display()
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Of Functions, Objects, and Methods-I NEED HELP PLEASE Benjamin Kaplan <benjamin.kaplan@case.edu> - 2011-06-08 13:34 -0700
csiph-web