[issue34085] doc Improve wording on classmethod/staticmethod

2019-03-25 Thread Cheryl Sabella


Change by Cheryl Sabella :


--
versions:  -Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34085] doc Improve wording on classmethod/staticmethod

2019-03-25 Thread Cheryl Sabella

Cheryl Sabella  added the comment:

Thanks for the report and the PR, Andrés!

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34085] doc Improve wording on classmethod/staticmethod

2019-03-25 Thread miss-islington


miss-islington  added the comment:


New changeset b23b08623a46cef841038ee32948020692ef1b35 by Miss Islington (bot) 
in branch '3.7':
bpo-34085: Improve wording on classmethod/staticmethod (GH-8228)
https://github.com/python/cpython/commit/b23b08623a46cef841038ee32948020692ef1b35


--

___
Python tracker 
<https://bugs.python.org/issue34085>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34085] doc Improve wording on classmethod/staticmethod

2019-03-25 Thread miss-islington


miss-islington  added the comment:


New changeset bd96393cda54044d81054225dcfc1b26374589a8 by Miss Islington (bot) 
in branch '2.7':
bpo-34085: Improve wording on classmethod/staticmethod (GH-8228)
https://github.com/python/cpython/commit/bd96393cda54044d81054225dcfc1b26374589a8


--
nosy: +miss-islington

___
Python tracker 
<https://bugs.python.org/issue34085>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34085] doc Improve wording on classmethod/staticmethod

2019-03-25 Thread miss-islington


Change by miss-islington :


--
pull_requests: +12493

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34085] doc Improve wording on classmethod/staticmethod

2019-03-25 Thread Cheryl Sabella


Cheryl Sabella  added the comment:


New changeset 548cb6060ab9d5a66931ea2be4da08c2c72c9176 by Cheryl Sabella (Andre 
Delfino) in branch 'master':
bpo-34085: Improve wording on classmethod/staticmethod (#8228)
https://github.com/python/cpython/commit/548cb6060ab9d5a66931ea2be4da08c2c72c9176


--
nosy: +cheryl.sabella

___
Python tracker 
<https://bugs.python.org/issue34085>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34085] doc Improve wording on classmethod/staticmethod

2019-03-25 Thread miss-islington


Change by miss-islington :


--
pull_requests: +12494

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34085] doc Improve wording on classmethod/staticmethod

2018-07-10 Thread Andrés Delfino

Change by Andrés Delfino :


--
keywords: +patch
pull_requests: +7766
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34085] doc Improve wording on classmethod/staticmethod

2018-07-10 Thread Andrés Delfino

New submission from Andrés Delfino :

1. The classmethod definition reads:

"""
The @classmethod form is a function decorator – see the description of function 
definitions in Function definitions for details.

It can be called either on the class (such as C.f()) or on an instance (such as 
C().f())
"""

The second paragraph seems like talking about the classmethod function instead 
of a class method. The same goes for staticmethod.

2. The staticmethod definition reads:

"""
It can be called either on the class (such as C.f()) or on an instance (such as 
C().f()). The instance is ignored except for its class.
"""

"The instance is ignored except for its class." seems to have been copied from 
classmethod definition.

3. There is redundant text:

"see the description of function definitions in Function definitions"

"consult the documentation on the standard type hierarchy in The standard type 
hierarchy"

PR fixes this.

--
assignee: docs@python
components: Documentation
messages: 321390
nosy: adelfino, docs@python
priority: normal
severity: normal
status: open
title: doc Improve wording on classmethod/staticmethod
type: enhancement
versions: Python 2.7, Python 3.6, Python 3.7, Python 3.8

___
Python tracker 
<https://bugs.python.org/issue34085>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5982] classmethod, staticmethod: expose wrapped function

2009-05-28 Thread Raymond Hettinger

Raymond Hettinger rhettin...@users.sourceforge.net added the comment:

r73005 and r73006

--
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5982
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5982] classmethod, staticmethod: expose wrapped function

2009-05-20 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc amaur...@gmail.com added the comment:

Is there a difficulty I did not see? Here is a patch.

--
keywords: +patch
nosy: +amaury.forgeotdarc
Added file: http://bugs.python.org/file14021/staticmethod_func.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5982
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5982] classmethod, staticmethod: expose wrapped function

2009-05-20 Thread Raymond Hettinger

Changes by Raymond Hettinger rhettin...@users.sourceforge.net:


--
assignee:  - amaury.forgeotdarc
resolution:  - accepted

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5982
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5982] classmethod, staticmethod: expose wrapped function

2009-05-19 Thread George Sakkis

George Sakkis george.sak...@gmail.com added the comment:

I don't remember the exact use case but it had to do with making a
decorator robust enough to work for different kinds of callables (and a
few common non-callables such as classmethod/staticmethod). It's not a
show stopper by any means but I thought it would be easy (if not
trivial) to implement, and regardless of actual use cases I don't see a
reason to keep the function hidden.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5982
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5982] classmethod, staticmethod: expose wrapped function

2009-05-19 Thread Raymond Hettinger

Raymond Hettinger rhettin...@users.sourceforge.net added the comment:

I am all for exposing the __func__ directly but don't immediately see
how to do it.

--
assignee: rhettinger - 

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5982
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5982] classmethod, staticmethod: expose wrapped function

2009-05-15 Thread Terry J. Reedy

Terry J. Reedy tjre...@udel.edu added the comment:

Having to bind and unbind a classmethod to get at the function is
definitely a bit weird, and also susceptible to changing implementation,
but do you have a practical use case to motivate the effort needed?

In Py3, '__func__' replaced 'im_func', and that is the name to use if
the attribute is added.  A change in 3.2 is at least as likely as a
change in 2.7.

--
nosy: +tjreedy
versions: +Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5982
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5982] classmethod, staticmethod: expose wrapped function

2009-05-11 Thread Raymond Hettinger

Changes by Raymond Hettinger rhettin...@users.sourceforge.net:


--
assignee:  - rhettinger
nosy: +rhettinger

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5982
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5982] classmethod, staticmethod: expose wrapped function

2009-05-09 Thread George Sakkis

New submission from George Sakkis george.sak...@gmail.com:

It would be nice if classmethod/staticmethod exposed the wrapped
function as a read-only attribute/property. Currently the function can
be retrieved indirectly but it's obscure (and perhaps not always
correct, I'm not sure):

In [147]: def f():pass
   .: 

In [148]: c = classmethod(f)

In [149]: s = staticmethod(f)

In [150]: c.__get__(1).im_func is f
Out[150]: True

In [151]: s.__get__(1) is f
Out[151]: True

--
messages: 87511
nosy: gsakkis
severity: normal
status: open
title: classmethod, staticmethod: expose wrapped function
type: feature request
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue5982
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: classmethod staticmethod

2007-07-25 Thread Gabriel Genellina
En Tue, 24 Jul 2007 21:55:17 -0300, Alex Popescu  
[EMAIL PROTECTED] escribió:

 Neil Cerutti [EMAIL PROTECTED] wrote in news:eRwpi.36813$G23.28496
 @newsreading01.news.tds.net:
 On 2007-07-25, Alex Popescu [EMAIL PROTECTED] wrote:
 As a matter of style, how do you figure out that class_list is
 a class attribute and not an instance attribute? (I don't
 remember seeing anything in the PEP describing the coding
 style).

 Check out dir(MyClass) and dir(MyClass()) for some insight, if it
 turns out that it matters.

 I must confess that I am a bit confused by this advise, as both are
 returning exactly the same thing.

Perhaps he meant to say vars(MyClass) and vars(MyClass())

 Preferably, the user of a class
 doesn't have to really think about it much.
 I know that this would be prefered, but in case you are getting 3rd party
 code and you modify a class attribute without knowing it is a class
 attribute then you may get into trouble (indeed the real problem is with
 the designer of the 3rd party code, but still I think it is a valid
 concern).

Well, you should read its documentation before modifying 3rd. party  
code... :)

If you access (read) an attribute through an instance (let's say, you  
write x = self.name inside a method) the attribute is first searched in  
the instance, and when not found, in the class (The actual rules are more  
complicated but this will suffice for now). If you assign an attribute, it  
is always set on the instance (never on the class). So you can use a class  
attribute as a default value for an instance attribute. For this use case,  
you don't care whether it's an instance attribute or class attribute:

py class Title:
...   color = white
...   def __init__(self, text, color=None):
... self.text = text
... if color is not None:
...   self.color = color
...
py t1 = Title(Hello)
py vars(t1)
{'text': 'Hello'}
py t1.color
'white'
py Title.color
'white'
py t1.color = red
py vars(t1)
{'color': 'red', 'text': 'Hello'}
py Title.color
'white'
py t2 = Title(Goodbye, blue)
py vars(t2)
{'color': 'blue', 'text': 'Goodbye'}


-- 
Gabriel Genellina

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classmethod staticmethod

2007-07-25 Thread Bruno Desthuilliers
Alex Popescu a écrit :
 Bruno Desthuilliers [EMAIL PROTECTED] wrote 
 in news:[EMAIL PROTECTED]:
 
 
 
[snip...]


Not necessarily - you can access class attributes from within an 
instance method (but obviously a classmethod cannot access instance 
attributes).
 
 
 What I am doing wrong here then:
 
 class MyClass(object):
   class_list = ['a', 'b']
 
   def instance_method(self):
 print instance_method with class list %s % class_list
 
 o = MyClass()
 o.instance_method()
 
 Traceback (most recent call last):
   File stdin, line 1, in module
   File stdin, line 4, in instance_method
 NameError: global name 'class_list' is not defined

The answer is in the error message. There's no local definition of 
'class_list' in function 'instance_method', and no global definition of 
'class_list' in the module. If you want to access MyClass.class_list in 
function instance_method, you need to use a fully qualified name, ie 
either self.class_list[1], self.__class__.class_list[2], 
type(self).class_list[3] or MyClass.class_list[4]

[1] this one is ok in 'read mode' since attributes not found in the 
instance's __dict__ will be looked up in the class's __dict__ (and then 
in parent's classes __dict__), but be warned that something like 
'self.class_list = []' will create an instance attribute of the same 
name, shadowing the class one. This is one of the (in)famous Python gotchas.

[2]  [3] Those two ones are equivalent. [3] is cleaner since it avoids 
direct access to an implementation attribute, but [2] is faster since it 
avoids a function call. In both cases, the lookup will be what one would 
expect in OO, that is first on the concrete class, then in the parents 
classes.

[4] Only use this one if you really want to bypass inheritance.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classmethod staticmethod

2007-07-25 Thread Neil Cerutti
On 2007-07-25, Alex Popescu [EMAIL PROTECTED] wrote:
 Neil Cerutti [EMAIL PROTECTED] wrote in news:eRwpi.36813$G23.28496
 @newsreading01.news.tds.net:

 On 2007-07-25, Alex Popescu [EMAIL PROTECTED] wrote:
 As a matter of style, how do you figure out that class_list is
 a class attribute and not an instance attribute? (I don't
 remember seeing anything in the PEP describing the coding
 style).
 
 Check out dir(MyClass) and dir(MyClass()) for some insight, if it
 turns out that it matters. 

 I must confess that I am a bit confused by this advise, as both
 are returning exactly the same thing.

Oops! I misthought myself.

I was thinking of MyClass.__dict__.keys() and
MyClass().__dict__.keys().

-- 
Neil Cerutti
To succeed in the world it is not enough to be stupid, you must also be well-
mannered. --Voltaire
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classmethod staticmethod

2007-07-25 Thread Steven D'Aprano
On Wed, 25 Jul 2007 00:22:18 +, Alex Popescu wrote:

 Steven D'Aprano [EMAIL PROTECTED] wrote in
 news:[EMAIL PROTECTED]: 
 
 On Tue, 24 Jul 2007 21:35:58 +, Alex Popescu wrote:
 
 Neil Cerutti [EMAIL PROTECTED] wrote in
 news:[EMAIL PROTECTED]: 
 
 On 2007-07-24, Alex Popescu [EMAIL PROTECTED] wrote:
 Bruno Desthuilliers
 [EMAIL PROTECTED] wrote in
 news:[EMAIL PROTECTED]: 


 [snip...]

 
 Use self.class_list when you want to use inheritance.
 
 
 As a matter of style, how do you figure out that class_list is a class 
 attribute and not an instance attribute? (I don't remember seeing anything 
 in the PEP describing the coding style).


The whole point of inheritance is that you don't care where the attribute
is (the instance, the class, a parent class...) just that it exists.



-- 
Steven.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classmethod staticmethod

2007-07-25 Thread Steven D'Aprano
On Wed, 25 Jul 2007 00:55:17 +, Alex Popescu wrote:

 Neil Cerutti [EMAIL PROTECTED] wrote in news:eRwpi.36813$G23.28496
 @newsreading01.news.tds.net:
 
 On 2007-07-25, Alex Popescu [EMAIL PROTECTED] wrote:
 As a matter of style, how do you figure out that class_list is
 a class attribute and not an instance attribute? (I don't
 remember seeing anything in the PEP describing the coding
 style).
 
 Check out dir(MyClass) and dir(MyClass()) for some insight, if it
 turns out that it matters. 
 
 I must confess that I am a bit confused by this advise, as both are 
 returning exactly the same thing.
 
 Preferably, the user of a class
 doesn't have to really think about it much.
 
 I know that this would be prefered, but in case you are getting 3rd party 
 code and you modify a class attribute without knowing it is a class 
 attribute then you may get into trouble (indeed the real problem is with 
 the designer of the 3rd party code, but still I think it is a valid 
 concern).

# warning: doesn't consider slots
if attribute in instance.__dict__:
print instance attribute
elif attribute in instance.__class__.__dict__:
print class attribute
else:
print either no attribute at all, or in a parent class



-- 
Steven.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classmethod staticmethod

2007-07-24 Thread Marc 'BlackJack' Rintsch
On Tue, 24 Jul 2007 03:19:05 +, james_027 wrote:

 python's staticmethod is the equivalent of java staticmethod right?

Correct.  `staticmethod` is essentially just a function moved into a class
and accessible at the class object and instances of that class.

As Python opposed to Java has functions, `staticmethod` isn't that useful.

 with classmethod, I can call the method without the need for creating
 an instance right? since the difference between the two is that
 classmethod receives the class itself as implicti first argument. From
 my understanding classmethod are for dealing with class attributes?

It's possible to access class attributes and, maybe more important, it's
possible to call the class to return an instance.  So if you call a
`classmethod` on a subclass an instance of that subclass is returned. 
Silly example:

class A(object):
def __init__(self, x, y):
print 'init A'
self.x = x
self.y = y

@classmethod
def from_str(cls, string):
return cls(*map(float, string.split(',')))


class B(A):
def __init__(self, x, y):
print 'init B'
A.__init__(self, x, y)


def main():
B.from_str('42,23')

Ciao,
Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classmethod staticmethod

2007-07-24 Thread Bruno Desthuilliers
james_027 a écrit :
 hi,
 
 python's staticmethod is the equivalent of java staticmethod right?

IIRC, yes. A 'staticmethod' is in fact nothing more than a function 
attached to a class, and which can be called on the class or an instance 
of. Note that since Python supports modules and functions, staticmethods 
are of little practical use.

 with classmethod, I can call the method without the need for creating
 an instance right? since the difference between the two is that
 classmethod receives the class itself as implicti first argument. 

Yes.

 From
 my understanding classmethod are for dealing with class attributes?

Not necessarily - you can access class attributes from within an 
instance method (but obviously a classmethod cannot access instance 
attributes).

 Can somebody teach me the real use of classmethod  staticmethod?

The 'real' use is (are) the one(s) you'll find. FWIW, I use 
staticmethods for helper functions that don't need access to the class 
or instance but are too specific to a class to be of any use as plain 
functions. Which is not a very frequent case. Classmethods are more 
usefull - mostly as alternate constructors or utility methods for an 
alternate constructor, but there are other possible uses (sorry, I have 
no concrete example at hand).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classmethod staticmethod

2007-07-24 Thread james_027
hi,

 The 'real' use is (are) the one(s) you'll find. FWIW, I use
 staticmethods for helper functions that don't need access to the class
 or instance but are too specific to a class to be of any use as plain
 functions. Which is not a very frequent case. Classmethods are more
 usefull - mostly as alternate constructors or utility methods for an
 alternate constructor, but there are other possible uses (sorry, I have
 no concrete example at hand).

You mean like the example from Marc

Thanks
james

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classmethod staticmethod

2007-07-24 Thread Bruno Desthuilliers
james_027 a écrit :
 hi,
 
 The 'real' use is (are) the one(s) you'll find. FWIW, I use
 staticmethods for helper functions that don't need access to the class
 or instance but are too specific to a class to be of any use as plain
 functions. Which is not a very frequent case. Classmethods are more
 usefull - mostly as alternate constructors or utility methods for an
 alternate constructor, but there are other possible uses (sorry, I have
 no concrete example at hand).
 
 You mean like the example from Marc

Marc's example is typically an alternate constructor. This is indeed one 
of the most obvious use case of classmethod, but what I meant is that 
there are others cases where classmethods can help.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classmethod staticmethod

2007-07-24 Thread Neil Cerutti
On 2007-07-24, Alex Popescu [EMAIL PROTECTED] wrote:
 Bruno Desthuilliers [EMAIL PROTECTED] wrote 
 in news:[EMAIL PROTECTED]:



 [snip...]

 
 Not necessarily - you can access class attributes from within an 
 instance method (but obviously a classmethod cannot access instance 
 attributes).


 What I am doing wrong here then:

 class MyClass(object):
   class_list = ['a', 'b']

   def instance_method(self):
 print instance_method with class list %s % class_list

There's no implicit self or class for Python identifiers.

The name class_list must be quailified: self.class_list or
MyClass.class_list.

-- 
Neil Cerutti
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classmethod staticmethod

2007-07-24 Thread Alex Popescu
Neil Cerutti [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 On 2007-07-24, Alex Popescu [EMAIL PROTECTED] wrote:
 Bruno Desthuilliers [EMAIL PROTECTED]
 wrote in news:[EMAIL PROTECTED]:


 [snip...]


 class MyClass(object):
   class_list = ['a', 'b']

   def instance_method(self):
 print instance_method with class list %s % class_list
 
 There's no implicit self or class for Python identifiers.
 
 The name class_list must be quailified: self.class_list or
 MyClass.class_list.
 

After more investigation I have figured this out by myself, but thanks for 
the details.
Now I am wondering if in the above case there is a prefered way:
MyClass.class_list or self.__class__.class_list? (IMO the 2nd is more safe 
in terms of refactorings).

./alex
--
.w( the_mindstorm )p.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classmethod staticmethod

2007-07-24 Thread Steven D'Aprano
On Tue, 24 Jul 2007 21:35:58 +, Alex Popescu wrote:

 Neil Cerutti [EMAIL PROTECTED] wrote in
 news:[EMAIL PROTECTED]: 
 
 On 2007-07-24, Alex Popescu [EMAIL PROTECTED] wrote:
 Bruno Desthuilliers [EMAIL PROTECTED]
 wrote in news:[EMAIL PROTECTED]:


 [snip...]


 class MyClass(object):
   class_list = ['a', 'b']

   def instance_method(self):
 print instance_method with class list %s % class_list
 
 There's no implicit self or class for Python identifiers.
 
 The name class_list must be quailified: self.class_list or
 MyClass.class_list.
 
 
 After more investigation I have figured this out by myself, but thanks for 
 the details.
 Now I am wondering if in the above case there is a prefered way:
 MyClass.class_list or self.__class__.class_list? (IMO the 2nd is more safe 
 in terms of refactorings).

Consider what happens when you sub-class:

class MyClass(object):
class_list = [1, 2, 3]
def method(self, x):
return sum(MyClass.class_list) + x

class MySubclass(MyClass):
class_list = ['a', 'b', 'c'] # over-ride the class attribute

expecting_a_string = MySubclass().method('x')


Use a direct reference to MyClass.class_list when you want a direct
reference to MyClass regardless of which instance or class you are calling
from.

Use self.class_list when you want to use inheritance.

Use self.__class__.class_list when you have an instance method and you
need the class it belongs to.

Use a classmethod and the first argument (by convention called klass
or cls) when you don't care about the instance and just want the class.



-- 
Steven.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classmethod staticmethod

2007-07-24 Thread Alex Popescu
Steven D'Aprano [EMAIL PROTECTED] wrote in
news:[EMAIL PROTECTED]: 

 On Tue, 24 Jul 2007 21:35:58 +, Alex Popescu wrote:
 
 Neil Cerutti [EMAIL PROTECTED] wrote in
 news:[EMAIL PROTECTED]: 
 
 On 2007-07-24, Alex Popescu [EMAIL PROTECTED] wrote:
 Bruno Desthuilliers
 [EMAIL PROTECTED] wrote in
 news:[EMAIL PROTECTED]: 


 [snip...]

 
 Use self.class_list when you want to use inheritance.
 

As a matter of style, how do you figure out that class_list is a class 
attribute and not an instance attribute? (I don't remember seeing anything 
in the PEP describing the coding style).

tia,
./alex
--
.w( the_mindstorm )p.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classmethod staticmethod

2007-07-24 Thread Neil Cerutti
On 2007-07-25, Alex Popescu [EMAIL PROTECTED] wrote:
 As a matter of style, how do you figure out that class_list is
 a class attribute and not an instance attribute? (I don't
 remember seeing anything in the PEP describing the coding
 style).

Check out dir(MyClass) and dir(MyClass()) for some insight, if it
turns out that it matters. Preferably, the user of a class
doesn't have to really think about it much.

-- 
Neil Cerutti
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: classmethod staticmethod

2007-07-24 Thread Alex Popescu
Neil Cerutti [EMAIL PROTECTED] wrote in news:eRwpi.36813$G23.28496
@newsreading01.news.tds.net:

 On 2007-07-25, Alex Popescu [EMAIL PROTECTED] wrote:
 As a matter of style, how do you figure out that class_list is
 a class attribute and not an instance attribute? (I don't
 remember seeing anything in the PEP describing the coding
 style).
 
 Check out dir(MyClass) and dir(MyClass()) for some insight, if it
 turns out that it matters. 

I must confess that I am a bit confused by this advise, as both are 
returning exactly the same thing.

 Preferably, the user of a class
 doesn't have to really think about it much.
 
I know that this would be prefered, but in case you are getting 3rd party 
code and you modify a class attribute without knowing it is a class 
attribute then you may get into trouble (indeed the real problem is with 
the designer of the 3rd party code, but still I think it is a valid 
concern).

tia,
./alex
--
.w( the_mindstorm )p.


-- 
http://mail.python.org/mailman/listinfo/python-list


classmethod staticmethod

2007-07-23 Thread james_027
hi,

python's staticmethod is the equivalent of java staticmethod right?

with classmethod, I can call the method without the need for creating
an instance right? since the difference between the two is that
classmethod receives the class itself as implicti first argument. From
my understanding classmethod are for dealing with class attributes?

Can somebody teach me the real use of classmethod  staticmethod?

Thanks
james

-- 
http://mail.python.org/mailman/listinfo/python-list