Last active
August 29, 2015 14:06
-
-
Save jakevdp/b20fbcff95939b00eda6 to your computer and use it in GitHub Desktop.
Google magic for IPython
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"name": "", | |
"signature": "sha256:f6b6aeb1dcdda419a4884edc04cdaf74f08daa2fb782b1247e3852be7a530566" | |
}, | |
"nbformat": 3, | |
"nbformat_minor": 0, | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"from IPython.display import IFrame\n", | |
"import webbrowser\n", | |
"\n", | |
"def google(self, arg):\n", | |
" phrase = arg.replace(' ', '+')\n", | |
" url = \"http://www.google.com/search?q={0}\".format(phrase)\n", | |
" \n", | |
" # Google prevents this. Cross origin stuff. Boo :(\n", | |
" #return IFrame(url, 600, 400)\n", | |
" \n", | |
" # We'll open a new browser window instead...\n", | |
" webbrowser.open(url)\n", | |
" \n", | |
" \n", | |
"ip = get_ipython()\n", | |
"ip.define_magic('google', google)" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 1 | |
}, | |
{ | |
"cell_type": "code", | |
"collapsed": false, | |
"input": [ | |
"%google ipython notebook" | |
], | |
"language": "python", | |
"metadata": {}, | |
"outputs": [], | |
"prompt_number": 2 | |
} | |
], | |
"metadata": {} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment