No enemies of the People will be guillotined during this talk.
Who cares?
IPython 0.0.1 was introduced in 2001, before I had even heard of Python. For years, I considered myself a Python programmer while barely knowing a thing about IPython. I knew it had tab-completion; that was nice. And a bunch of "magic" commands that I didn't have time to research.
source: Blue's Clues Wikia
So what is it?
So something big is going on here. You don't want to be a counter-revolutionary, do you?
In [6]:
%%ruby
say = "if that's your thing"
puts say.upcase
In [7]:
%%bash
for ext in py ipy ipynb; do
ls *.$ext
done
In [2]:
%%script perl
my $files = `ls *.ipynb`;
print $files;
In [3]:
files = !ls *.ipynb
files
Out[3]:
In [4]:
for ext in ('html', 'ipy', 'ipynb'):
!ls *.{ext}
In [5]:
!rm -f *.ipynb.2
!ls *_*.ipynb*
In [6]:
notebooks = !ls *_*.ipynb
for nb_name in notebooks:
name_stem = nb_name.split('.ipynb')[0]
!cp {name_stem}.ipynb {name_stem.upper()}.ipynb.2
!ls *_*.ipynb*
“Man is by nature a social animal; an individual who is unsocial naturally and not accidentally is either beneath our notice or more than human. Society is something that precedes the individual. Anyone who either cannot lead the common life or is so self-sufficient as not to need to, and therefore does not partake of society, is either a beast or a god. ”
― Aristotle, Politics
Probablistic Programming & Bayesian Methods for Hackers by Cameron Davidson-Pilon
Let's make a coin.
In [15]:
import random
class Coin(object):
def __init__(self, state=None):
if state in ('heads', 'tails'):
self.state = state
else:
self.flip()
def flip(self):
self.state = random.choice(('heads', 'tails'))
def __repr__(self):
return "Coin('%s')" % self.state
coin = Coin()
coin
Out[15]:
That was boring. Let's display
In [16]:
from IPython.display import Image
coin.flip()
if coin.state == 'heads':
i = Image('images/CENT_OBV.jpg')
else:
i = Image('images/CENT_REV.jpg')
In [17]:
i
Out[17]:
That was not very object-oriented.
In [18]:
class Coin(object):
def __init__(self, state=None):
if state in ('heads', 'tails'):
self.state = state
else:
self.flip()
def flip(self):
self.state = random.choice(('heads', 'tails'))
def __repr__(self):
return "Coin('%s')" % self.state
def _repr_html_(self):
return '''a <span style="color:gold">Coin</span>
showing <span style="font-size:40px;font-weight:bold;"
>%s</span>''' % self.state
In [19]:
Coin()
Out[19]:
In [20]:
class Coin(object):
def __init__(self, state=None):
if state in ('heads', 'tails'):
self.state = state
else:
self.flip()
def flip(self):
self.state = random.choice(('heads', 'tails'))
def __repr__(self):
return "Coin('%s')" % self.state
coin_faces = {'heads': 'CENT_OBV.jpg', 'tails': 'CENT_REV.jpg'}
def _repr_html_(self):
# return '<img src="files/images/%s" />' % self.coin_faces[self.state]
return '<img src="files/images/%s" />' % self.coin_faces[self.state]
# The notebook and the .reveal presentation work differently here!
In [21]:
Coin()
Out[21]:
In [22]:
from IPython.display import YouTubeVideo
# a talk about IPython at Sage Days at U. Washington, Seattle.
# Video credit: William Stein.
YouTubeVideo('1j_HxD4iLn8')
Out[22]:
Inline TeX in Markdown: $\sqrt{3x-1}+(1+x)^2$
In [69]:
from IPython.display import Math
Math(r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx')
Out[69]:
In [34]:
>>> def cheer(word):
... for letter in word:
... print('%s!' % letter.upper())
...
>>> cheer('ohio')
In [35]:
%load http://catherinedevlin.pythoneers.com/posertalk.py
In [ ]:
import random
word = 'python'
result = ''.join(l.upper()
for l in word
if random.choice((True, False))
else l)
result
ipython nbconvert --format reveal presentation.ipynb
cd nbconvert_build
python -m SimpleHTTPServer 8000 &
Requires IPython 1.0
Every notebook is a JSON file with ".ipynb" extension
In [23]:
!head presentation.ipynb
Share a link to a workbook
or a link to a bundle
... and your collaborators don't even need Python...
The IPython kernel executes code; the client(s) is/are separate
In [1]:
%connect_info
IPython Notebook in IDEs
Calls for a magnet to release the ball and a photo gate!
%quickref
, %lsmagic
In [ ]: