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


Groups > comp.lang.python > #7309

Re: Of Functions, Objects, and Methods-I NEED HELP PLEASE

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: Of Functions, Objects, and Methods-I NEED HELP PLEASE
Date 2011-06-09 10:25 -0700
Organization > Bestiaria Support Staff <
References <mailman.30.1307563778.11593.python-list@python.org> <rqednZoL2ezK8m3QnZ2dnUVZ5hKdnZ2d@giganews.com>
Newsgroups comp.lang.python
Message-ID <mailman.56.1307640355.11593.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, 08 Jun 2011 23:59:35 -0700, Larry Hudson <orgnut@yahoo.com>
declaimed the following in gmane.comp.python.general:

> > 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
>
 
> 2:  This won't work to append to your list anyway... each time you call dogAppend() it will 
> clear out any existing list and result in a list of one element, a tuple of (name, breed).  You 
> can do exactly the same thing with a single line:  return [(self.name, self.breed)]
>
	Worse than that... The first time dogAppend is called on an instance
of Dog, it replaces the dogAppend method with a binding to the (single
element) list created by the method.
 
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Of Functions, Objects, and Methods-I NEED HELP PLEASE Cathy James <nambo4jb@gmail.com> - 2011-06-08 15:09 -0500
  Re: Of Functions, Objects, and Methods-I NEED HELP PLEASE John Gordon <gordon@panix.com> - 2011-06-08 20:42 +0000
  Re: Of Functions, Objects, and Methods-I NEED HELP PLEASE Larry Hudson <orgnut@yahoo.com> - 2011-06-08 23:59 -0700
    Re: Of Functions, Objects, and Methods-I NEED HELP PLEASE Ethan Furman <ethan@stoneleaf.us> - 2011-06-09 05:54 -0700
    Re: Of Functions, Objects, and Methods-I NEED HELP PLEASE Ethan Furman <ethan@stoneleaf.us> - 2011-06-09 06:10 -0700
    Re: Of Functions, Objects, and Methods-I NEED HELP PLEASE Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2011-06-09 10:25 -0700
    Re: Of Functions, Objects, and Methods-I NEED HELP PLEASE Larry Hudson <orgnut@yahoo.com> - 2011-06-09 23:07 -0700

csiph-web