Working with Descriptors
Emeka
emekamicro at gmail.com
Sun Dec 11 23:32:00 EST 2011
Hello All,
How do I get the __set__ to work here?
import random
class Die(object):
def __init__(self, sides=6):
self.sides = sides
def __get__(self, instance, owner):
return int(random.random() * self.sides) + 1
def __set__(self, instance, value):
instance.__dict__[self.side] = value
class Game(object):
d6 = Die()
d10 = Die(sides=10)
d20 = Die(sides=20)
Game.d3 = 90 (This failed)
Regards,
Emeka
--
*Satajanus Nig. Ltd
*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111212/4a5ffdb9/attachment-0001.html>
More information about the Python-list
mailing list