Source

pyptug / islanders / pythonhist.txt

Full commit
# attributes are your friend
class Puppy(object):
    age=1
benji=Puppy()
benji.age
dir(Puppy)
class Puppy(object):
    age=None
    dog_years=None

benji=Puppy()
benji.age=1

# problem...
benji.dog_years
# solution
help(property)



# I need getters/setters, panic? no.
class Puppy(object):
    def getage(self): return self._age
    def setage(self,value): self._age=value
    age=property(getage,setage)

benji=Puppy()
benji.age=2
benji.age




class Puppy(object):
    @property
    def age(self): return self._age
    @age.setter
    def age(self,value): self._age=value



# saving time by importing dogyears instead of typing it
# dogyears.DogYears() is a descriptor
from dogyears import *
class Puppy(object):
    @property
    def age(self): return self._age
    @age.setter
    def age(self,value): self._age=value
    dog_years=DogYears()

# last line above, dog_years will look like a property, but is a
# custom descriptor
    
benji=Puppy()
benji.age=1.2
benji.dog_years
quit()