Skip to content

Instantly share code, notes, and snippets.

@bcho
Created November 13, 2012 04:54
Show Gist options
  • Select an option

  • Save bcho/4063980 to your computer and use it in GitHub Desktop.

Select an option

Save bcho/4063980 to your computer and use it in GitHub Desktop.
#coding: utf-8
'''
Descriptor example.
'''
class Meter(object):
def __init__(self, value=0.0):
self.value = float(value)
def __get__(self, instance, owner):
return self.value
def __set__(self, instance, value):
self.value = float(value)
class Foot(object):
def __get__(self, instance, owner):
return instance.meter * 3.2808
def __set__(self, instance, value):
instance.meter = float(value) / 3.2808
class Distance(object):
meter = Meter()
foot = Foot()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment