0

how can initialize empty objects in python ?

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

thanks

2
  • refer the online documentation: python.org/download/releases/2.2.3/descrintro Commented Oct 14, 2010 at 9:43
  • -1: No Code. Please update the question to include actual code that shows your problem. Commented Oct 14, 2010 at 10:02

1 Answer 1

4

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

class C(object):
  def __init__(self, val):
    self.val = val
Sign up to request clarification or add additional context in comments.

2 Comments

So, I don't need to add members to the class.. just declare them inside the constructor for the first time
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.