{ "metadata": { "name": "breakout" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# IPython Intro Breakout Session\n", "\n", "Interactive exploration\n", "-----------------------\n", "\n", "I have shown you the Zen of Python. But if you search through all of the python\n", "source code, you will not find the word \"Zen\" anywhere.\n", "\n", "\n", "\n", "Use ``, `?` and `??` on the `this` module to decode this string:" ] }, { "cell_type": "code", "collapsed": true, "input": [ "import this\n", "\n", "secret = \"Tbbq Wbo! abj tb fvta hc sbe gur znvyvat yvfg bire ng vclguba.bet\"" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The Zen of Python, by Tim Peters\n", "\n", "Beautiful is better than ugly.\n", "Explicit is better than implicit.\n", "Simple is better than complex.\n", "Complex is better than complicated.\n", "Flat is better than nested.\n", "Sparse is better than dense.\n", "Readability counts.\n", "Special cases aren't special enough to break the rules.\n", "Although practicality beats purity.\n", "Errors should never pass silently.\n", "Unless explicitly silenced.\n", "In the face of ambiguity, refuse the temptation to guess.\n", "There should be one-- and preferably only one --obvious way to do it.\n", "Although that way may not be obvious at first unless you're Dutch.\n", "Now is better than never.\n", "Although never is often better than *right* now.\n", "If the implementation is hard to explain, it's a bad idea.\n", "If the implementation is easy to explain, it may be a good idea.\n", "Namespaces are one honking great idea -- let's do more of those!\n" ] } ], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Timing information\n", "------------------\n", "\n", "\n", "\n", "Josh mentioned that there are two range commands, `range` and `xrange`. \n", "\n", "\n", "\n", "Run the code below to see which one is faster, and then read the documentation for the two to see why this is the case." ] }, { "cell_type": "code", "collapsed": true, "input": [ "timeit?" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": true, "input": [ "%timeit range(100)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": true, "input": [ "%timeit xrange(100)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Configuration file options\n", "--------------------------\n", "\n", "Create the stub default profile (if you haven't already)\n", "\n", "\n", "\n", " $ ipython profile create\n", "\n", "\n", "\n", "This will create the stubs for the default profile\n", "\n", "now you can change these defaults.\n", "\n", "\n", "\n", "To find where your profile is stored:\n", "\n", "\n", "\n", " In [1]: import IPython\n", "\n", " In [2]: IPython.utils.path.locate_profile()\n", "\n", "\n", "\n", "Example:if you want the `_` and `__` methods to show up by default when doing tab-completion \n", "\n", "\n", "\n", " c.IPCompleter.omit__names\n", "\n", "Another example: you can add your own startup message (or execute your desired commands at startup) like I have:\n", "\n", " .../profile_default/startup/README\n", "\n", "\n", "\n", "\n", "\n", "\n", " " ] }, { "cell_type": "code", "collapsed": false, "input": [ "import IPython\n", "IPython.utils.path.locate_profile()" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 2, "text": [ "u'/home/pi/.ipython/profile_default'" ] } ], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "IPython.utils.path.locate_profile()+'/startup/README'" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "pyout", "prompt_number": 3, "text": [ "u'/home/pi/.ipython/profile_default/startup/README'" ] } ], "prompt_number": 3 }, { "cell_type": "code", "collapsed": true, "input": [ "cat IPython.utils.path.locate_profile()+'/startup/README'" ], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }