Hello Jean-Michel,
On 2010-08-12 16:06, Jean-Michel Pichavant wrote:
> Eric J. Van der Velden wrote:
> Should be
>
> class C:
> n = 0
> def __init__(self):
>self.__class__.n+=1
>C.n+=1 # equivalent to this line (I prefer this one, more
> readable, less refactor-friendly)
Eric J. Van der Velden wrote:
> I have,
>
> class C:
> n=0
> def __init__(s):
> __class__.n+=1
>
>
> I do
C()
>
> This is fine. But of what thing I am taking the __class__ of?
> I can also do
>
> @staticmethod
> def p():
> p
In article
<72151646-65cb-47bb-bd55-e7eb67577...@z10g2000yqb.googlegroups.com>,
"Eric J. Van der Velden" wrote:
> Hello,
>
> I have,
>
> class C:
> n=0
> def __init__(s):
> __class__.n+=1
>
>
> I do
> >>> C()
>
> This is fine.
No it's not, at least in Pytho
Eric J. Van der Velden wrote:
Hello,
I have,
class C:
n=0
def __init__(s):
__class__.n+=1
Should be
class C:
n = 0
def __init__(self):
self.__class__.n+=1
C.n+=1 # equivalent to this line (I prefer this one, more
readable, less refactor-
Hello,
I have,
class C:
n=0
def __init__(s):
__class__.n+=1
I do
>>> C()
This is fine. But of what thing I am taking the __class__ of?
I can also do
@staticmethod
def p():
print(__class__.n)
>>> C.p()
1
Thanks,
Eric J.
--