Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Not Tom Eastman

439 views

Published on

A humorous lightning talk from PyCon NZ 2016.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Not Tom Eastman

  1. 1. Not Tom Eastman by Not Katie McLaughlin
  2. 2. class TomEastman(object): def whoami(self): return 'Tom Eastman’ tom_eastman = TomEastman() print(tom_eastman.whoami()) Tom Eastman
  3. 3. class KatieMcLaughlin(object): def whoami(self): return 'Katie McLaughlin’ katie_mclaughlin = KatieMcLaughlin() print(katie_mclaughlin.whoami()) Katie McLaughlin
  4. 4. if not tom_eastman: print('not Tom Eastman') else: print('Tom Eastman') Tom Eastman
  5. 5. if not TomEastman: print('not Tom Eastman') else: print('Tom Eastman') Tom Eastman
  6. 6. if katie_mclaughlin is not tom_eastman: print('Katie is not Tom') else: print('Katie is Tom') Katie is not Tom
  7. 7. if katie_mclaughlin is not katie_mclaughlin: print('Katie is not Katie') else: print('Katie is Katie') Katie is Katie
  8. 8. if not isinstance(katie_mclaughlin, TomEastman): print('Katie McLaughlin') else: print('not Katie McLaughlin') Katie McLaughlin
  9. 9. from wrapt import ObjectProxy class KatieMcLaughlin(ObjectProxy): pass tom_eastman = TomEastman() katie_mclaughlin = KatieMcLaughlin(tom_eastman) print(tom_eastman.whoami()) print(katie_mclaughlin.whoami()) Tom Eastman Tom Eastman
  10. 10. if isinstance(katie_mclaughlin, TomEastman): print('Tom Eastman') else: print('not Tom Eastman') Tom Eastman
  11. 11. if isinstance(katie_mclaughlin, KatieMcLaughlin): print('Katie McLaughlin') else: print('not Katie McLaughlin') Katie McLaughlin
  12. 12. if type(katie_mclaughlin) == TomEastman: print('Tom Eastman') else: print('not Tom Eastman') not Tom Eastman
  13. 13. What have we learnt?
  14. 14. More than one way to skin a cat
  15. 15. not == != is is not isinstance() type() __class__ __bool__() __int__() id()
  16. 16. class GrahamDumpleton(object): def whoami(self): return 'Graham Dumpleton' graham_dumpleton = GrahamDumpleton() print(not isinstance(graham_dumpleton, (TomEastman, KatieMcLaughlin))) True

×