Python: How should I make instance variables available?

Posted by swisstony on Stack Overflow See other posts from Stack Overflow or by swisstony
Published on 2010-06-03T08:10:23Z Indexed on 2010/06/03 8:14 UTC
Read the original article Hit count: 164

Filed under:
|

Suppose I have:

class myclass:
  def __init__(self):
    self.foo = "bar"

where the value of foo needs to be available to users of myclass. Is it OK to just read the value of foo directly from an instance of myclass? Should I add a get_foo method to myclass or perhaps add a foo property? What's the best practice here?

© Stack Overflow or respective owner

Related posts about python

Related posts about class-design