$30 off During Our Annual Pro Sale. View Details »

Job Security (in Python) (Christopher Neugebauer)

Job Security (in Python) (Christopher Neugebauer)

PyCon Canada

August 25, 2013
Tweet

More Decks by PyCon Canada

Other Decks in Education

Transcript

  1. >>> c = Collection() >>> c.set_spam(“eggs”) Traceback (most recent call

    last): File "<stdin>", line 1, in <module> File "<stdin>", line 10, in __getattribute__ TypeError: instancemethod expected at least 2 arguments, got 0
  2. Help on Collection in module __main__ object: class Collection(Magic) |

    Method resolution order: | Collection | Magic | __builtin__.object | | Methods defined here: | | get_spam(self) | | set_spam(self, default)
  3. TRANSLATE = (("get","_bork_"), ("set","_bork_"), ("canhas" , "get"), ("ihasa" , "set"))

    class Magic(object): def __getattribute__(self, attribute): oa = attribute for (key,val) in TRANSLATE: attribute = attribute.replace(key, val) try: return object. __getattribute__(self,attribute) except AttributeError: return type(object. __getattribute__(self, oa))