Sessions at PyCon US 2012 in E3

Your current filters are…

  • Space: E3

Friday 9th March 2012

  • Introduction to Metaclasses

    by Luke Sneeringer

    Python's metaclasses grant the Python OOP ecosystem all the power of more complex object inheritance systems in other languages, while retaining for most uses the simplicity of the straightforward class structures most developers learn when being introduced to object-oriented programming. This talk is an explanation of metaclasses: first, what they are, and second, how to use them.

    • Metaclasses
    • Introduction (2.5m)
    • Python's metaclasses grant the Python OOP ecosystem all the power of more complex object inheritance systems in other languages, while retaining the simplicity of the straightforward class structure that traditional C++ and Java programmers learned, and is taught in programming courses.
    • Classes are Objects, Too! (5m)
    • Classes are first-class objects in Python, like functions/methods
    • Classes, like other objects, can be assigned to variables and passed as arguments
    • ...and this ability is one of the tricks in the reusable code toolbox
    • Concept: Metaclasses generate classes. (5m)
    • The hierarchy starts with "type"
    • Classes are themselves instances of their metaclasses
    • By extension, classes provide code that runs when instances are created, while metaclasses provide code that runs when classes are created.
    • Remember the "analogies" section on standardized tests in the United States (and many other countries)?
    • Babylon 5 : J. Michael Strazynski :: Star Trek : ___
    • Instances : Classes :: Classes : Metaclasses
    • Think about a self-enclosed machine that creates, say, t-shirts. The machine is the class; the individual shirts are the instances. The guy who builds the t-shirt machines is the metaclass.
    • Concrete Code Examples (10m)
    • will cover 3.0 and 2.7
    • (stub: I haven't decided what my example will be yet)
    • Is metaclassing wise? (2.5m)
    • There's nothing inherently wrong or bad about it. Furthermore, sometimes it's by far the best way to solve a problem.
    • Beware, though: Some people find metaclassing confusing.
    • "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." (Brian Kernighan)
    • Questions (5m)

    At 10:50am to 11:30am, Friday 9th March

    In E3, Santa Clara Convention Center

    Coverage video

  • The Art of Subclassing

    by Raymond Hettinger

    All problems have simple, easy-to-understand, logical wrong answers. Subclassing in Python is no exception. Avoid the common pitfalls and learn everything you need to know about making effective use of inheritance in Python.

    Avoid the common pitfalls and learn everything you need to know about how subclass in Python.

    • Overriding and extending
    • Calling your parents
    • The ellipse / circle problem
    • What does a subclass mean?
    • Liskov Substitution Principle
    • Open Closed Principle
    • Facts of life when subclassing builtin types
    • Cooperative Multiple Inheritance
    • Common subclassing patterns
    • Use of the double underscore

    At 11:30am to 12:10pm, Friday 9th March

    In E3, Santa Clara Convention Center

    Coverage video

  • Stop Writing Classes

    by Jack Diederich

    Classes are great but they are also overused. This talk will describe examples of class overuse taken from real world code and refactor the unnecessary classes, exceptions, and modules out of them.

    Classes must be nouns but not every noun must be a class. If your class only has two methods and one of them is init you probably meant to write a function.
    MuffinMail recently refactored their API; it went from 20 classes scattered in 22 modules down to 1 class just 15 lines long. It was a welcome change, but we'll further refactor that down to a single function 3 lines long.

    The Python stdlib is an example of a namespace that is relatively flat. You won't find packages that consist of a single module defining an exception, and you won't find many exceptions at all - just 165 kinds in 200k lines of code. That's a tiny ratio compared to most projects including Django.

    Of course there are things, like containers, that should be classes. As a final example we'll add a Heap type to the heapq module (admit it, you already have one in your utils.py).

    At 12:10pm to 12:40pm, Friday 9th March

    In E3, Santa Clara Convention Center

    Coverage video

  • The Magic of Metaprogramming

    by Jeff Rush

    Learn the magic of writing programs that monitor, alter and react to the execution of program code by responding to imports, changes to variables, calls to functions and invocations of the builtins. This talk goes beyond the static world of metaclasses and class decorators.

    Learn the magic of writing programs that monitor, alter and react to the execution of program code by responding to imports, changes to variables, calls to functions and invocations of the builtins. This talk goes beyond the static world of metaclasses and class decorators.

    We'll cover how to slide a class underneath a module to intercept reads/writes, place automatic type checking over your object attributes and use stack peeking to make selected attributes private to their owning class. We'll cover import hacking, metaclasses, descriptors and decorators and graphically describe how they work internally. Source examples and color technical diagrams.

    Table-of-Contents
    What is Metaprogramming?
    Tools At Our Disposal
    Orientation Diagram: What is Metaprogramming
    First Third of Talk: Import Hooking
    Sample Problem #1: Subclassing an Embedded Class
    A Solution to #1: Post-Import Hooking
    A Solution to #1 (Packaged Up)
    Alternate Solution: Pre-Import Hooking
    What Does a Subclassed Module Look Like?
    Some Benefits of Subclassing Modules
    2nd Third of Talk: Metaclasses
    Orientation Diagram: Instances, Classes and Metaclasses
    Facts About Metaclasses
    Example #2: Define a Class from an SQL Table Definition
    Example Problem #2 (cont'd)
    Metaclasses versus Class Decorators
    About Meta-Inheritance
    Example #3: Log the Arguments/Return Value of Method Calls
    Lull After Metaclasses, Before Descriptors
    Last Third of Talk: Descriptors
    Python's Mechanism of Attribute Lookup
    When to Use Which Lookup Mechanism
    Example 4: Overriding getattr
    Example 4: Using a Descriptor Instead
    Python's Mechanism of Attribute Lookup (descriptors)
    So What is a descriptor again?
    Where are descriptors used?
    Example 5: Caching an Attribute Value
    Example 6: Declare an Attribute Private to a Class
    Example 7: Tracking Changes in a Value

    At 1:45pm to 2:40pm, Friday 9th March

    In E3, Santa Clara Convention Center

  • Interfaces and Python

    by Eric Snow

    In 2.6, Python introduced the Abstract Base Classes. Before that we had "protocols" (and we still do). In this talk we'll look at how the general concept of interfaces fits into today's Python. We'll also look at some of the alternate proposals of the past, some of the controversies around ABCs, and the direction interfaces might go in the future.

    Talk Outline:

    • What are Interfaces? (3 min)
    • modeling strict abstraction
    • precedents in other languages
    • Interfaces in Python (6 min)
    • duck-typing
    • Python "protocols"
    • past proposals (PEP 245)
    • how Python "interfaces" are different
    • Newer Interface Support (11 min)
    • annotations
    • Abstract Base Classes
    • why run-time validation?
    • ABC vs. duck-typing
    • Third-party Libraries (5 min)
    • Peak's PyProtocols
    • zope.interface
    • Twisted
    • What Next? (3 min)
    • strict interfaces
    • compile-time validation
    • an example interface library

    For more comprehensive coverage of interfaces in Python, check out this reference: http://readthedocs.org/docs/refe...

    At 2:40pm to 3:20pm, Friday 9th March

    In E3, Santa Clara Convention Center

    Coverage video

  • Decorators and Context Managers

    by Dave Brondsema

    Learn how decorators and context managers work, see several popular examples, and get a brief intro to writing your own. Decorators wrap your functions to easily add more functionality. Context managers use the 'with' statement to make indented blocks magical. Both are very powerful parts of the python language; come learn how to use them in your code.

    Decorators wrap or modify your functions. They are functions themselves, so you can pass parameters to them. You can wrap a function with multiple decorators too. We'll cover how to use decorators in all those situations and how to write them too. Examples will be demonstrated with:

    • @property
    • @memoize
    • mock/patch
    • TurboGears
    • Django
    • Allura

    Context managers wrap a block of code using the 'with' statement to do something on the way into the block and something on the way out. Opening and closing a file is a very common case, but there is a lot more you can do. Examples include:

    • modifying state
    • capturing stdout
    • mock/patch
    • locks
    • timing
    • transactions

    More about decorators: http://www.python.org/dev/peps/p...

    More about context managers: http://www.python.org/dev/peps/p...
    http://docs.python.org/library/c...

    At 3:20pm to 3:50pm, Friday 9th March

    In E3, Santa Clara Convention Center

  • Python Metaprogramming for Mad Scientists and Evil Geniuses

    by Walker Hale

    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.

    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.

    At 4:25pm to 5:20pm, Friday 9th March

    In E3, Santa Clara Convention Center

    Coverage video note

  • Through The Ether And Back Again: What Happens To A Packet When You Send It

    by glyph

    Many - perhaps even most - Python software involves a network, at least a little bit. You've probably written some yourself. But do you really know what happens - to your kernel, to your ethernet card, to Python - when you call socket.send()? Come to this talk and find out: if you dare.

    At 5:20pm to 6:00pm, Friday 9th March

    In E3, Santa Clara Convention Center

    Coverage video

Saturday 10th March 2012

  • What you need to know about datetimes

    by Taavi Burns

    `time`, `datetime`, and `calendar` from the standard library are a bit messy. Find out what to use where and how (particularly when you have users in many timezones), and what extra modules you might want to look into.

    • Defining an "instant"
    • Silly timezones
    • In the words of Armin Ronacher:
    • Always measure and store time in UTC
    • Do not use offset aware datetimes
    • If you are taking in user input that is in local time, immediately convert it to UTC. If that conversion would be ambiguous let the user know.
    • Rebase for Formatting (then throw away that filthy offset aware datetime object)
    • Emil Mikulik on time
    • UTC vs UT1 vs UNIX time
    • Timezones are a presentation-layer problem!
    • Getting timezone information: pytz vs python-dateutil
    • Naïve vs Aware datetimes
    • datetime.now(tz) vs datetime.utcnow()
    • What does tm_isdst actually mean
    • datetime vs struct_time vs UNIX time
    • How to store them?
    • Using UNIX time: time.gmtime() and calendar.timegm()
    • Using MySQL (date, datetime, timestamp)
    • Using Postgres (date, timestamp)
    • Using Sqlite (text, real, integer)
    • To talk to JavaScript
    • Formatting with offsets
    • strftime and %z and friends, e.g. to simulate syslog log lines

    At 10:25am to 11:05am, Saturday 10th March

    In E3, Santa Clara Convention Center

    Coverage video

  • Storing, manipulating and visualizing timeseries using open source packages in Python

    by Jonathan Rocher

    Analyzing, storing and visualizing time-series efficiently are recurring though difficult tasks in various aspects of scientific data analysis such as meteorological forecasting, financial modeling, ... In this talk we will explore the current Python ecosystem for doing this effectively, comparing options, using only open source packages that are mature yet still under active development.

    At 11:05am to 11:45am, Saturday 10th March

    In E3, Santa Clara Convention Center

    Coverage video

  • Pragmatic Unicode, or, How do I stop the pain?

    by Ned Batchelder

    Python has great Unicode support, but it's still your responsibility to handle it properly. I'll do a quick overview of what Unicode is, but only enough to get your program working properly. I'll describe strategies to make your code work, and keep it working, without getting too far afield in Unicode la-la-land.

    Python has great Unicode support, but it's still your responsibility to handle it properly. Even expert programmers get tripped up with the encodings and decodings that can happen implicitly, throwing errors in unexpected places.

    This talk will present a quick overview of what Unicode is, why it exists, and how it works, but only enough to get your program working properly. Unicode can be intricate and fascinating, but really, who cares? You just want your code to work without throwing a UnicodeEncodeError every time an accented character sneaks in somehow.

    I'll describe strategies to make your code work, and keep it working, without getting too far afield in Unicode la-la-land.

    How Unicode is handled is one of the biggest changes in Python 3. I'll touch on what those changes are, and how you can use them to keep even your Python 2 code running smoothly.

    Outline
    Bytes vs. text
    ASCII, 8859-1, etc.
    Unicode
    Encodings
    Python 2: str vs unicode
    encode and decode
    implicit conversions!!
    Python 3: bytes vs str
    Everybody's happy!

    At 11:45am to 12:15pm, Saturday 10th March

    In E3, Santa Clara Convention Center

  • A Gentle Introduction to GIS

    by Jason Scheirer

    Datums! Coordinate systems! Map projections! Topologies! Spatial applications are a nebulous, daunting concept to most Pythonistas. This talk is a gentle introduction into the concepts, terminology and tools to demystify the world of the world.

    This talk will have multiple parts:

    • What is GIS?
    • Cartography
    • Analysis
    • Geodatabases
    • Types of data
    • Vector
    • Raster
    • How do you talk about spots on earth?
    • What is a datum and why does it matter?
    • Spatial reference systems: WUT?
    • Map projections: what's appropriate and what's web mercator
    • Great circle distances and geodesy (or, your lines are wrong and you should feel bad)
    • Analysis
    • Overlay operators
    • Clementini operators
    • Buffer, clip their friends
    • Will demonstrate concepts with commercial tools (the ArcGIS stack) and some open source (GDAL, OGR, QGIS).

    At 1:20pm to 2:15pm, Saturday 10th March

    In E3, Santa Clara Convention Center

  • Making maps with Python

    by Zain Memon

    Python makes it easy to store, query, and transform geodata. We will run through a handful of useful GIS libraries and patterns that let you do magical things with your maps. If you want to make maps that are more interactive and more interesting, this talk is for you.

    This talk will demystify the different parts of a usual map stack, including:

    GeoSpatial Datastores (RDBMS & NoSQL)
    Map servers (that query the geodata)
    Tile servers (that chunk the data into tiles and cache it)
    Browser UIs (and the difference between different Javascript slippy maps)

    At 2:15pm to 2:55pm, Saturday 10th March

    In E3, Santa Clara Convention Center

    Coverage video

  • Using fabric to standardize the development process

    by Ricardo Kirkner

    By ensuring consistency and repeatability in setting up the development environments of a team of developers, errors can be avoided (by automating repetitive tasks). It also helps by lowering the entry barrier for new developers, and letting existing developers focus on development tasks without having to worry about infrastructure or process issues.

    This talk will show how you can use fabric to standardize the different tasks that are commonly performed during the development process. Such tasks can be grouped into categories like:

    bootstrap: initializing the development environment
    database: managing the database
    testing: running tests
    lint: validating the code against different standards
    deploy: automating the deployment process

    At 2:55pm to 3:25pm, Saturday 10th March

    In E3, Santa Clara Convention Center

  • Spatial data and web mapping with Python

    by Paul Smith

    Spatial data are often seen as opaque to most developers, and while dealing with them does require a shift in approach from the data types we most regularly handle, they needn’t be the domain of specialists. High-quality Python libraries and Python-based applications exist for operating on and transforming spatial data, and for creating visualizations, including maps for presentation on the web.

    This talk will be an overview of the Python libraries and applications available for handling spatial and geospatial data and creating maps for the web. It will cover libraries for open and transforming spatial data formats and representations, spatial operators and predicates for queries and relationships, spatial indexes for efficient queries, and compositing and rendering map tiles, as well as desktop applications extensible with Python that replace much of the functionality of "enterprise" GIS software.

    At 4:00pm to 4:55pm, Saturday 10th March

    In E3, Santa Clara Convention Center

  • How CherryPy supports Python 2 and 3

    by Robert Brewer

    CherryPy was the first web framework to be made available for use with Python 3, and we tried several approaches to support both Python 2 and 3 before settling on one. Learn about the ups and the downs of each approach, and ways you can make your own porting project easier.

    The CherryPy project was the first web framework to support Python 3. At the same time, we needed to continue to support and improve the Python 2 implementation. It's taken plenty of time and lots of experimentation to find out the best way. We will explore four different ways to support both Python 2 and 3, commenting on the pros and cons of each.

    Intro
    Python 3 change highlights
    Special concerns for I/O, including WSGI
    Approach 1: 2to3
    Approach 2: separate branches
    Approach 3: setup.py switch
    Approach 4: compatibility layer
    Q&A

    At 4:55pm to 5:30pm, Saturday 10th March

    In E3, Santa Clara Convention Center

    Coverage video

Sunday 11th March 2012

  • Parsing Horrible Things with Python

    by Erik Rose

    If you've ever wanted to get started with parsers, here's your chance for a ground-floor introduction. A harebrained spare-time project gives birth to a whirlwind journey from basic algorithms to Python libraries and, at last, to a parser for one of the craziest syntaxes out there: the MediaWiki grammar that drives Wikipedia.

    Some languages were designed to be parsed. The most obvious example is Lisp and its relatives which are practically parsed when they hit the page. However, many others—including most wiki grammars—grow organically and get turned into HTML by sedimentary strata of regular expressions, all backtracking and warring with one another, making it difficult to output other formats or make changes to the language.

    We will explore the tools and techniques necessary to attack one of the hairiest lingual challenges out there: MediaWiki syntax. Join me for an introduction to the general classes of parsing algorithms, from the birth of the field to the state of the art. Learn how to pick the right one. Have a comparative look at a dozen different Python parsing toolkits. And finally, learn some optimization tricks to get a grammar going at a reasonable clip.

    At 12:00pm to 12:30pm, Sunday 11th March

    In E3, Santa Clara Convention Center

  • Building A Python-Based Search Engine

    by Daniel Lindsley

    Search is an increasingly common request in all types of applications as the amount of data all of us deal with continues to grow. The technology/architecture behind search engines is wildly different from what many developers expect. This talk will give a solid grounding in the fundamentals of providing search using Python to flesh out these concepts in a simple library.

    • Core concepts
    • Terminology
    • Document-based
    • Show basic starting code for a document
    • Inverted Index
    • Show a simple inverted index class
    • Stemming
    • N-gram
    • Show a tokenizer/n-gram processor
    • Fields
    • Show a document handler which ties it all together
    • Searching
    • Show a simple searcher (& the whole thing working together)
    • Faceting (likely no demo)
    • Boost (likely no demo)
    • More Like This
    • Wrap up

    At 1:30pm to 2:10pm, Sunday 11th March

    In E3, Santa Clara Convention Center

  • Parsing sentences with the OTHER natural language tool: LinkGrammar

    by Jeff Elmore

    Many of you are probably familiar with NLTK, the wonderful Natural Language Toolkit for Python. You may not be familiar with Linkgrammar, which is a sentence parsing system created at Carnegie Melon university. Linkgrammar is quite robust and works "out of the box" in a way that NLTK does not for sentence parsing.

    Abstract

    NLTK is a fantastic library with broad capabilities. But often I find that I want something that will just do what I want without my having to figure out all of the details. An example of this is sentence parsing. A quick google search for parsing sentences with NLTK returns a number of articles describing how to write your own grammar and define a parser based on that grammar and parse sentences. This is great for toy problems and education, but if you actually need to parse sentences "from the wild," writing your own grammar is a huge undertaking.

    Enter Linkgrammar. Linkgrammar was developed at Carnegie Melon university and is now maintained by the developers of Abiword as the basis for their grammar checking capabilities. It works nicely out of the box and is tolerant of irregularities found in authentic text.

    At 2:10pm to 2:55pm, Sunday 11th March

    In E3, Santa Clara Convention Center

    Coverage video