Browse Source

more examples of chapter 05

master
T. Meissner 10 years ago
parent
commit
0a3d7b8cd5
2 changed files with 52 additions and 0 deletions
  1. +15
    -0
      python_3_oop/chapter05/color.py
  2. +37
    -0
      python_3_oop/chapter05/silly.py

+ 15
- 0
python_3_oop/chapter05/color.py View File

@ -0,0 +1,15 @@
class Color:
def __init__(self, rgb_value, name):
self.rgb_value = rgb_value
self._name = name
def _set_name(self, name):
if not name:
raise Exception("Invalid name")
self._name = name
def _get_name(self):
return self._name
name = property(_get_name, _set_name)

+ 37
- 0
python_3_oop/chapter05/silly.py View File

@ -0,0 +1,37 @@
#class Silly:
#
# def _get_silly(self):
# print("You're getting silly")
# return self._silly
#
# def _set_silly(self, value):
# print("You're making silly {}".format(value))
# self._silly = value
#
# def _del_silly(self):
# print("Whoa, you're killing silly!")
# del self._silly
#
# silly = property(_get_silly, _set_silly, _del_silly,
# "This is a silly property")
# same as before but with decorators:
class Silly:
@property
def silly(self):
"This is a silly property"
print("You're getting silly")
return self._silly
@silly.setter
def silly(self, value):
print("You're making silly {}".format(value))
self._silly = value
@silly.deleter
def silly(self):
print("Whoa, you're killing silly!")
del self._silly

Loading…
Cancel
Save