0

how can initialize empty objects in python ?

I need to initialize my class members (for examples tk.frames, vtk visualizations etc)

thanks

2

1 Answer 1

4

Access the attributes of self in your __init__() method.

class C(object):
  def __init__(self, val):
    self.val = val
2
  • So, I don't need to add members to the class.. just declare them inside the constructor for the first time
    – aneuryzm
    Oct 14, 2010 at 11:28
  • 2
    Members added to the class directly become class attributes, and are shared across all instances of the class. This is rarely what is wanted for attributes other than methods. Oct 14, 2010 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.