Skip to content

Instantly share code, notes, and snippets.

@jeremyBanks
Created August 4, 2008 18:00
Show Gist options
  • Save jeremyBanks/3941 to your computer and use it in GitHub Desktop.
Save jeremyBanks/3941 to your computer and use it in GitHub Desktop.
[2010-01] some simple examples of using properties in python, probably not idiomatic
#!/usr/bin/env python
import sys
class Example(object):
@property
def readOnlyProperty(self):
print "Getting five"
return 5
__it = 6
def getWriteableProperty(self):
print "Getting it"
return self.__it
def setWriteableProperty(self, value):
print "Setting it"
self.__it = value
writeableProperty = property(getWriteableProperty, setWriteableProperty)
def main():
x = Example()
print x.readOnlyProperty
print x.writeableProperty
x.writeableProperty = 13
print x.writeableProperty
if __name__ == "__main__": sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment