Created
March 23, 2014 20:31
-
-
Save NotBobTheBuilder/9729390 to your computer and use it in GitHub Desktop.
Robot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixed - this needs to be a new-style class.
That is, in Python 2, the declaration must be
class Robot(object)