Skip to content

Instantly share code, notes, and snippets.

@bogsio
Created October 28, 2013 19:32
Show Gist options
  • Save bogsio/7203100 to your computer and use it in GitHub Desktop.
Save bogsio/7203100 to your computer and use it in GitHub Desktop.
Understanding Python descriptors #5
class User(object):
email = EmailField()
...
class Company(object):
contact = EmailField()
...
user1 = User()
user1.email = 'bogdan@mail.com'
print user1.email # bogdan@mail.com
user2 = User()
user2.email = 'example@mail.com'
print user2.email # example@mail.com
print user1.email # bogdan@mail.com
print user2.email # example@mail.com
company = Company()
company.contact = 'abc@company.com'
print company.contact # abc@company.com
print EmailField._EmailField__email_dict
# {0: 'bogdan@mail.com', 1: 'example@mail.com', 2: 'abc@company.com'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment