GET /api/v2/video/419
HTTP 200 OK Vary: Accept Content-Type: text/html; charset=utf-8 Allow: GET, PUT, PATCH, HEAD, OPTIONS
{ "category": "PyCon US 2011", "language": "English", "slug": "pycon-2011--what-would-you-do-with-an-ast", "speakers": [ "Matthew J Desmarais" ], "tags": [ "ast", "pycon", "pycon2011" ], "id": 419, "state": 1, "title": "What would you do with an ast?", "summary": "", "description": "What would you do with an ast?\n\nPresented by Matthew J Desmarais\n\nThe ast module in the Python (>= 2.6) standard library provides a\nrepresentation of python code in a python data structure. We'll begin with a\ndiscussion about what an abstract syntax tree is and why it's useful. We can\nthen talk about what's available in the ast module, how it works, and how you\ncan use it. This will be a practical session built around examples examining\nand modifying live ASTs.\n\nAbstract\n\nI would prefer to make this a 45 minute talk with examination of code samples.\n\nPython 2.6 introduced a new module in the standard library, ast. The first\nline of the ast documentation is, \"The ast module helps Python applications to\nprocess trees of the Python abstract syntax grammar.\" What this means is not\nobvious and many, if not most, python programmers won't know what this means.\nI will begin by talking about the idea of syntax tree and how it fits into the\npython execution lifecycle. I will also talk about the contents of the ast\nmodule. I will cover the available ast.Node subclasses and the provided helper\nfunctions, including the NodeVisitor and NodeTransformer. I will finish by\ntalking about how the ast module can be used to analyze Python code and how it\ncan be used to generate new code.\n\nI expect the time to break down roughly like this:\n\nIntroduction ( 5m )\n\n * Capacitor joke \n * What is an abstract syntax tree? \n * How they are used by the Python interpreter \n\nThe contents of the ast module (20 m)\n\n * The node subclasses and the ast ( 10m ) \n * How you get an ast. \n * code examples\n * ast.stmt vs. ast.expr \n * peculiarities \n * code examples \n * elif as syntactic sugar for \"if: else: if:\" \n * comparison operators \n * Why this is useful. \n * the ast is the \"truth\" of the program \n * code examples \n * tricky code \n * The ast module helpers ( 10m ) \n * visitor pattern \n * NodeVisitor \n * NodeTransformer \n * code examples \n\nWhat you do with an ast ( 15m )\n\n * Walking an ast \n * code examples \n * a simple visitor to gather variables by scope\n * Creating/Modifying an ast \n * code examples \n * rearrange imports transformer \n * naive \"rename all instances\" transformer \n * naive macro expansion transformer \n\nConclusion ( 5m )\n\n * Practical Applications \n * existing projects \n * visitors \n * checkers (pylint, pyflakes)\n * transformers \n * refactoring tools (rope)\n * When is it a good idea to use ast? \n\n", "quality_notes": "", "copyright_text": "Creative Commons Attribution-NonCommercial-ShareAlike 3.0", "embed": "", "thumbnail_url": "http://a.images.blip.tv/Pycon-PyCon2011WhatWouldYouDoWithAnAst198.png", "duration": null, "video_ogv_length": 220279145, "video_ogv_url": null, "video_ogv_download_only": false, "video_mp4_length": null, "video_mp4_url": "http://05d2db1380b6504cc981-8cbed8cf7e3a131cd8f1c3e383d10041.r93.cf2.rackcdn.com/pycon-us-2011/419_what-would-you-do-with-an-ast.mp4", "video_mp4_download_only": false, "video_webm_length": null, "video_webm_url": null, "video_webm_download_only": false, "video_flv_length": null, "video_flv_url": null, "video_flv_download_only": false, "source_url": "", "whiteboard": "", "recorded": "2011-03-11", "added": "2012-02-23T04:20:00", "updated": "2014-04-08T20:28:28.062" }