foo and _foo - about variables inside a class
Posted
by kame
on Stack Overflow
See other posts from Stack Overflow
or by kame
Published on 2010-04-21T13:47:40Z
Indexed on
2010/04/21
14:13 UTC
Read the original article
Hit count: 227
class ClassName(object):
"""
"""
def __init__(self, foo, bar):
"""
"""
self.foo = foo # read-write property
self.bar = bar # simple attribute
def _set_foo(self, value):
self._foo = value
def _get_foo(self):
return self._foo
foo = property(_get_foo, _set_foo)
a = ClassName(1,2)
#a._set_foo(3)
print a._get_foo()
When I print a._get_foo() the function _get_foo prints the variable self._foo . But where does it come from? self._foo and self.foo are different, aren't they?
© Stack Overflow or respective owner