David writes:
> Out of 'Abc.message' and 'self.message', which is the favoured
> convention?
It's not a matter of convention. They mean different things, so you use
each depending on what you mean.
> It would be very easy to accidentally override 'self.messages' with an
> instance attribute!
R
David a écrit :
(snip)
Out of 'Abc.message' and 'self.message', which is the favoured
convention? It would be very easy to accidentally override
'self.messages' with an instance attribute!
Only use 'Abc.message' if you want to make sure you get the Abc class
'message' attribute - that is, if
Chris Rebert a écrit :
(snip)
To access class-level variables from within instance methods of the
class, you have 2 options:
A. Use the class name, i.e. Abc.message
B. Reference the class indirectly, i.e. self.__class__.message
Or even simpler - *if* there's no synonym instance attribute:
=> s
Ben Finney writes:
> Right. So you use ‘Abc.message’ when you specifically want a class
> independent of any instance
That's “a class attribute independent of any instance”, of course.
--
\“Humanity has advanced, when it has advanced, not because it |
`\ has been sober, responsi
On Aug 19, 1:17 am, "Jan Kaliszewski" wrote:
> 19-08-2009 o 02:10:58 Jan Kaliszewski wrote:
>
> > The only ways to reach Abc's attribute 'message' from that method are:
> > * 'Abc.message'
> > * 'self.__class__.message'
> > * 'self.message' (unless there is an instance attribute 'message' which
>
19-08-2009 o 02:10:58 Jan Kaliszewski wrote:
The only ways to reach Abc's attribute 'message' from that method are:
* 'Abc.message'
* 'self.__class__.message'
* 'self.message' (unless there is an instance attribute 'message' which
overrides the class attribute).
And of course getattr(Abc), ge
19-08-2009 o 00:47:09 David wrote:
Hi all,
I'm trying to understand how scopes work within a class definition.
I'll quickly illustrate with an example. Say I had the following class
definition:
class Abc:
message = 'Hello World'
def print_message(self):
print message
instan
On Tue, 18 Aug 2009 15:47:09 -0700, David wrote:
> Hi all,
>
> I'm trying to understand how scopes work within a class definition. I'll
> quickly illustrate with an example. Say I had the following class
> definition:
>
> class Abc:
> message = 'Hello World'
>
> def print_message(self):
On Aug 19, 12:16 am, Chris Rebert wrote:
> On Tue, Aug 18, 2009 at 3:47 PM, David wrote:
> > Hi all,
>
> > I'm trying to understand how scopes work within a class definition.
> > I'll quickly illustrate with an example. Say I had the following class
> > definition:
>
> > class Abc:
> > message
On Tue, Aug 18, 2009 at 3:47 PM, David wrote:
> Hi all,
>
> I'm trying to understand how scopes work within a class definition.
> I'll quickly illustrate with an example. Say I had the following class
> definition:
>
> class Abc:
> message = 'Hello World'
>
> def print_message(self):
>
10 matches
Mail list logo