Skip to content

Instantly share code, notes, and snippets.

@jakevdp
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakevdp/b20fbcff95939b00eda6 to your computer and use it in GitHub Desktop.
Save jakevdp/b20fbcff95939b00eda6 to your computer and use it in GitHub Desktop.
Google magic for IPython
Display the source blob
Display the rendered blob
Raw
{
"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