{ "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", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import this\n", "\n", "secret = \"Tbbq Wbo! abj tb fvta hc sbe gur znvyvat yvfg bire ng vclguba.bet\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Solution\n", "--------\n", "\n", "Using Tab-completion, you should have figured out that `this` module has the following things\n", "\n", " this.c # a character\n", " this.d # a dictionary, mapping letters to letters\n", " this.s # the string of the Zen of Python poem, encoded like our `secret`\n", " this.c # a counter that's only used in creating `this.d`\n", "\n", "I found out how `this.c` is actually used by looking at source code using `this??`" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "this." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "this??" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "this.d" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Aha! The last line of the this module is what does the actual decoding!\n", "\n", "let's just tweak it a bit" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "\"\".join([this.d.get(c, c) for c in secret])" ] }, { "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", " %config 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", " ~/.ipython/profile_default/startup/README\n", "\n", "\n", "\n", "\n", "\n", "\n", " " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import IPython\n", "IPython.utils.path.locate_profile()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "IPython.utils.path.locate_profile()+'/startup/README'" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "aperture_code = '''\"\"\" \n", " ,=:;//;:-,. \n", " ,;%+,./H#M@MM@@@H: . \n", " ,/X@MMMH%-,=%MM@M@@M+ +X/, \n", " -+@MMMM@MMMMX;,-+HM@@M$ ;MM@+- \n", " ./@#M@M@HHHXXXXX+- .;X@MX -M@@M@; \n", " .,=:=-=---. =%@, HM@@MM%, \n", " ;+%%%$$XH%- ,. XM@@@#@= \n", " :MM@MMMM@;. $M@M@/.-= \n", " $M@@@MM+. /MM$- /@X \n", " -@@@@#X= . :@: :H@M@,\n", " =M@M@; -H/ . ,XMM@@@,\n", " .$#%..+MM% ,+@M@@@@H.\n", " ;= ;HM@MX ./HMM@MMMM/ \n", " ,XM@@@@H. , =$@HHX$%+%/ \n", " ,XM@@@@@,.H%- .--------=. \n", " .%MM@@M= XMM$:. -+%$$$XXHHH@@@MM%. \n", " =XMMM/ +M@MMH+-,;H#MM@MM@MMMX= \n", " =%M% ;M@@@MM@$=.-$@#M@M@%= \n", " ,= =@MMMMMMM#H/,-+$+:, \n", " .-:/+%%%%++= \n", " \n", " There is research to be done \"\"\"\n", "import time\n", "time.sleep(.1)\n", "print __doc__'''" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "filepath = IPython.utils.path.locate_profile()+'/startup/aperture.py'\n", "with open(filepath, 'w') as f:\n", " f.write(aperture_code)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.4.3" } }, "nbformat": 4, "nbformat_minor": 0 }