Created
March 22, 2012 11:22
-
-
Save mingyc/2157757 to your computer and use it in GitHub Desktop.
A simple Circle module with radius setter.
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 Circle(object): | |
def __init__(self, value): | |
self.radius = None | |
self.set_radius(value) | |
def set_radius(self, value): | |
if value < 0: | |
raise ValueError('radius must be positive: {0}'.format(value)) | |
self.radius = value | |
circle = Circle(3) | |
print circle.radius | |
circle.set_radius(10) # ugly usage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment