[Tutor] assign all parameters of __init__ to class variables?
Steven D'Aprano
steve at pearwood.info
Fri Nov 4 07:32:38 CET 2011
Alex Hall wrote:
> I'm sorry, I misspoke (well, mistyped anyway). I have a couple
> class-level variables, but most of them are set in the __init__ so
> that every instance gets a fresh copy of them. Thatnks for the
> responses.
Ah I see, or at least I think I see. Possibly we're talking at
cross-purposes.
When you talk about "class-level variables", to me that means class
attributes: attributes of a class, like this:
class Spam:
x = "this is at the class level"
as opposed to "instance-level variables", which I would interpret as
instance attributes:
class Ham:
def __init__(self):
self.x = "this is on the instance"
If you mean something different from this, then we're talking past each
other.
--
Steven
More information about the Tutor
mailing list