[Tutor] assign all parameters of __init__ to class variables?

Alex Hall mehgcap at gmail.com
Fri Nov 4 14:08:37 CET 2011


No, I mean what you said. My class has one or two class-level:
class myClass:
  x=5

and a lot of instance-level:
  def __init__(self, p1, p2...):
    self.__dict__.update(locals())

On 11/4/11, Steven D'Aprano <steve at pearwood.info> wrote:
> 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
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>


-- 
Have a great day,
Alex (msg sent from GMail website)
mehgcap at gmail.com; http://www.facebook.com/mehgcap


More information about the Tutor mailing list