Python Metaprogramming for Mad Scientists and Evil Geniuses

Type:
Talk
Audience level:
Experienced
Category:
Core Python (Language, Stdlib)
March 9th 4:25 p.m. – 5:20 p.m.

Description

This talk covers the power and metaprogramming features of Python that cater to mad scientists and evil geniuses. This will also be of interest to others who just want to use of Python in a more power (hungry) way. The core concept is that you can synthesize functions, classes and modules without a direct correspondence to source code. You can also mutate third-party objects and apps.

Abstract

This talk covers the power and metaprogramming features of Python that cater to mad scientists and evil geniuses. This will also be of interest to others who just want to use of Python in a more power (hungry) way.

Users of Python are not limited to the usual model of a one-to-one correspondence between source code and live objects. Python allows you to synthesize functions, classes and modules without a direct correspondence to source code. You can mutate third-party objects, classes, modules and applications through monkey patching -- changing their behavior without altering their source code. You can even "chop-up" third-party objects to create new objects from the pieces. Find out how to unleash your inner Mad Scientist!

  • Thesis: Python is an ideal language for both:
    • Mad Scientists
    • Evil Geniuses
  • Mad Scientist versus Evil Genius
    • Mad Scientist: creating new things because it's cool
    • Evil Genius: practical applications
  • Typical Mad Science Goals
    • Create new living code objects from scraps without corresponding source code.
    • Mutate third-party code to suite our purposes without modifying the third-party source code.
  • Synthetics
    • Synthetic Functions
    • Synthetic Classes
    • Synthetic Modules
    • Applications of Synthetics
  • Monkey Patching
    • Monkey Patching Modules
    • Monkey Patching Classes
    • Monkey Patching Instances
  • sitecustomize.py
  • Dealing with Angry Villagers
  • Limitations: When not to do this
  • For the Evil Geniuses

Although most of the material is presented from the point of view of the Mad Scientist, it is equally useful to the Evil Genius.

Since the Python community prides itself on diversity, I should emphasize that the sane, the non-evil, and "do-gooders" are all welcome.