Skip to content

Instantly share code, notes, and snippets.

@NotBobTheBuilder
Created March 23, 2014 20:31
Show Gist options
  • Save NotBobTheBuilder/9729390 to your computer and use it in GitHub Desktop.
Save NotBobTheBuilder/9729390 to your computer and use it in GitHub Desktop.
Robot
class Robot():
def __init__(self):
self._heading = 0
@property
def heading(self):
print("Getting " + str(self._heading))
return self._heading
@heading.setter
def heading(self, val):
print("Setting to " + str(val))
self._heading = val
myrobot = Robot()
myrobot.heading
myrobot.heading = 1
"""
Why the difference?
$ python minimal.py
Getting 0
$ python3 minimal.py
Getting 0
Setting to 1
"""
@NotBobTheBuilder
Copy link
Author

Fixed - this needs to be a new-style class.
That is, in Python 2, the declaration must be class Robot(object)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment