<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>scienceoss.com &#187; IPython</title>
	<atom:link href="http://scienceoss.com/categories/python/ipython/feed/" rel="self" type="application/rss+xml" />
	<link>http://scienceoss.com</link>
	<description>useful tidbits for using open source software in science</description>
	<lastBuildDate>Wed, 26 May 2010 03:34:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Test the speed of your code interactively in IPython</title>
		<link>http://scienceoss.com/test-the-speed-of-your-code-interactively-in-ipython/</link>
		<comments>http://scienceoss.com/test-the-speed-of-your-code-interactively-in-ipython/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 16:49:54 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[IPython]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[speed]]></category>

		<guid isPermaLink="false">http://scienceoss.com/test-the-speed-of-your-code-interactively-in-ipython/</guid>
		<description><![CDATA[So you&#8217;ve come up with a couple of ways to solve a problem in code. But how do you decide which way is the best? One criterion to decide on is to use the one that makes the most sense to you. Another criterion is to use the version that is fastest. Here&#8217;s how to [...]]]></description>
			<content:encoded><![CDATA[<p>So you&#8217;ve come up with a couple of ways to solve a problem in code.  But how do you decide which way is the best?  One criterion to decide on is to use the one that makes the most sense to you.  Another criterion is to use the version that is fastest.  Here&#8217;s how to quickly determine which way is fastest using the interactive interpreter IPython.<span id="more-109"></span></p>
<p>Recently I posted a couple of <a href="http://scienceoss.com/sort-one-list-by-another-list/">different ways to sort one list by another list</a>.  But how to decide which one is faster?</p>
<p>I like using the <span class="c">timeit</span> magic function in IPython to time Python code.  It takes, as its argument, a single Python expression.  <span class="c">timeit</span> then returns the time it took the CPU to run that code.   Problem is, <span class="c">timeit</span> takes a single expression, but those sorting methods are multi-line statements. </p>
<p>No matter, we just wrap them in a function, and call the function as a single expression.  Here are the functions I&#8217;ll be testing:</p>
<pre class="brush: python; title: ; notranslate">
import numpy
def method1(x,y):
    z = zip(x,y)
    z.sort()
    return zip(*z)

def method2(x,y):
    inds = numpy.argsort(x)
    return numpy.take(y,inds)

def method3(x,y):
    xa = numpy.array(x)
    ya = numpy.array(y)
    inds = xa.argsort()
    return ya[inds]
</pre>
<p>OK, we need some lists to use for the test sorting.  How about the ones used from the previously mentioned post:</p>
<pre class="brush: python; title: ; notranslate">
people = ['Jim', 'Pam', 'Micheal', 'Dwight']
ages = [27, 25, 4, 9]
</pre>
<p>And now, to test each method.  If it&#8217;s a really fast bit of code, <span class="c">timeit</span> will run it many times (here, 100,000 or 10,000 times) to get a good estimate of how long it takes.</p>
<pre class="brush: python; title: ; notranslate">timeit method1(ages,people)  # 100000 loops, best of 3: 3.6 µs per loop
timeit method2(ages,people)  # 10000 loops, best of 3: 63.7 µs per loop
timeit method3(ages,people)  # 10000 loops, best of 3: 36.8 µs per loop</pre>
<p>These results suggest that the first method is an order of magnitude faster.  But wait a minute, method3() converts the input lists into arrays . . . I bet that takes some time.  How fast does it run if the data are already in an array?  Time for another function.  This one expects its arguments to be arrays already.</p>
<pre class="brush: python; title: ; notranslate">def method3a(x,y):
    inds = x.argsort()
    return y[inds]</pre>
<p>And let&#8217;s convert ages and people into arrays ahead of time so we can use <span class="c">method3a</span>:</p>
<pre class="brush: python; title: ; notranslate">array_ages = numpy.array(ages)
array_people = numpy.array(people)
</pre>
<p>The other methods still ought to run when the data are arrays.  Here are the results on my machine for all the methods so far:</p>
<pre class="brush: python; title: ; notranslate">timeit method1(array_ages, array_people)   # 100000 loops, best of 3: 6.29 µs per loop
timeit method2(array_ages, array_people)   # 100000 loops, best of 3: 6.88 µs per loop
timeit method3(array_ages, array_people)   # 100000 loops, best of 3: 5.12 µs per loop
timeit method3a(array_ages, array_people)  # 100000 loops, best of 3: 4.02 µs per loop</pre>
<p>So it looks like if the data are already in an array form, method3a looks like the fastest.</p>
<p>Let&#8217;s see if the results are consistent with a larger dataset, where you might actually perceive a difference in speed.</p>
<pre class="brush: python; title: ; notranslate">#The test arrays
xa = numpy.random.random(100000)
ya = numpy.random.random(100000)

# The test arrays converted into test lists
xlist = xa.tolist()
ylist = ya.tolist()

# Test the speed of sorting arrays
timeit method1(xa,ya)  # 10 loops, best of 3: 443 ms per loop
timeit method2(xa,ya)  # 10 loops, best of 3: 20.6 ms per loop
timeit method3(xa,ya)  # 10 loops, best of 3: 18.9 ms per loop
timeit method3a(xa,ya) # 10 loops, best of 3: 19.1 ms per loop

# Test the speed of sorting lists
timeit method1(xlist,ylist)  # 10 loops, best of 3: 391 ms per loop
timeit method2(xlist,ylist)  # 10 loops, best of 3: 51.3 ms per loop
timeit method3(xlist,ylist)  # 10 loops, best of 3: 55.1 ms per loop
# (can't test method3a since it won't accept lists)</pre>
<p>Interesting.  When your data is already in an array, <span class="c">method3</span> (which converts x and y into arrays) is actually faster than <span class="c">method3a</span> (which assumes they are already arrays)!  Not by much, but I wouldn&#8217;t have expected that two extra lines of code would actually make it faster.</p>
<p>The final results show that the answer depends on what form your data are in:
<ul>
<li>For small lists, use <span class="c">method1</span>.</li>
<li>For large lists, use <span class="c">method2</span>.</li>
<li>For small arrays, use <span class="c">method3a</span>.</li>
<li>For large arrays, use <span class="c">method3</span>.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://scienceoss.com/test-the-speed-of-your-code-interactively-in-ipython/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Run programs in the background in IPython</title>
		<link>http://scienceoss.com/running-programs-in-the-background-in-ipython/</link>
		<comments>http://scienceoss.com/running-programs-in-the-background-in-ipython/#comments</comments>
		<pubDate>Sun, 02 Dec 2007 17:36:35 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[IPython]]></category>
		<category><![CDATA[IPython help]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://scienceoss.com/?p=40</guid>
		<description><![CDATA[You can start another thread in IPython to run a program in the background. bg go() runs the function go() in another thread jobs[0].status tells you what&#8217;s going on with that job jobs[0].result the result of the job jobs? see more help on this part of IPython]]></description>
			<content:encoded><![CDATA[<p>You can start another thread in IPython to run a program in the background. <span id="more-40"></span></p>
<table border="0" cellpadding="4" >
<tbody>
<tr>
<td class="command">bg go()</td>
<td>runs the function <span class="c">go()</span> in<br />
another thread</td>
</tr>
<tr>
<td class="command">jobs[0].status</td>
<td>tells you what&#8217;s going on with that job</td>
</tr>
<tr>
<td class="command">jobs[0].result</td>
<td>the result of the job</td>
</tr>
<tr>
<td class="command">jobs?</td>
<td>see more help on this part of IPython</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://scienceoss.com/running-programs-in-the-background-in-ipython/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debug and optimize your code in IPython</title>
		<link>http://scienceoss.com/debugging-and-optimizing-in-ipython/</link>
		<comments>http://scienceoss.com/debugging-and-optimizing-in-ipython/#comments</comments>
		<pubDate>Sun, 02 Dec 2007 17:34:22 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[IPython]]></category>
		<category><![CDATA[IPython help]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://scienceoss.com/?p=39</guid>
		<description><![CDATA[One great thing about Python is the interactive debugger, which lets you inspect the value of variables at the point an error occurred. Of course, IPython integrates nicely with the Python debugger and makes debugging code a cinch. xmode Plain plain exception mode xmode Context shows source code around an error xmode Verbose alo shows [...]]]></description>
			<content:encoded><![CDATA[<p>One great thing about Python is the interactive debugger, which lets you inspect the value of variables at the point an error occurred.  Of course, IPython integrates nicely with the Python debugger and makes debugging code a cinch.<span id="more-39"></span></p>
<table border="0" cellpadding="4" >
<tbody>
<tr>
<td class="command">xmode Plain</td>
<td>plain exception mode</td>
</tr>
<tr>
<td class="command">xmode Context</td>
<td>shows source code around an error</td>
</tr>
<tr>
<td class="command">xmode Verbose</td>
<td>alo shows the arguments going into the function<br />
where the error occured</td>
</tr>
<tr>
<td class="command">pdb</td>
<td>Toggls automatic <span class="c">pdb</span>. Upon<br />
hitting an error, you are dropped into the Python debugger. See {ln: Python debugger} for details.</td>
</tr>
<tr>
<td class="command">run -d scriptName</td>
<td>starts the debugger from the beginning of the<br />
script</td>
</tr>
<tr>
<td class="command">debug</td>
<td>go into the debugger right away.</td>
</tr>
</tbody>
</table>
<p style="margin-bottom: 0in">&nbsp;</p>
<p style="margin-bottom: 0in"></p>
<h2>IPython from any script</h2>
<p style="margin-bottom: 0in">IPython can be embedded in a script.&nbsp; Wherever the command ipshell() occurs in your code, an IPython shell will pop up, giving you full access to everything in the namespace of the script.&nbsp; This is extremely useful if you want to add interactive functionality to a program, or need to check on some variables without using the debugger.</p>
<pre class="prettyprint">
<span class=
"prettyprint">from IPython.Shell import IPShellEmbed </span>
ipshell = IPShellEmbed()
ipshell()  # add this wherever you would like to open an IPython window
</pre>
<p style="margin-bottom: 0in">Each ipshell() will open up a new shell.&nbsp; You have to close the newly opened shell using <span class="c">exit()</span> or <span class="c">Exit</span> before the script will continue.</p>
<p style="margin-bottom: 0in">&nbsp;</p>
<p style="margin-bottom: 0in">Checking performance of your code</p>
<p style="margin-bottom: 0in">&nbsp;</p>
<table border="0" cellpadding="4" >
<tbody>
<tr>
<td class="command">time sum(range(10000000))</td>
<td>time the summing of the list of numbers 1 through<br />
ten million and print how long it took</td>
</tr>
<tr>
<td class="command">timeit sum(range(1000))</td>
<td>automatically figures out if it should try a couple times to get an accurate estimate for commands that take very little time.&nbsp; Prints average time.</td>
</tr>
<tr>
<td class="command">prun go()</td>
<td>runs the profiler on the function, <span class="c">go()</span>.&nbsp; The output from the profiler shows how long it took for each part of the script to run.&nbsp; <span class="c">prun</span> works on expressions, not files.</td>
</tr>
<tr>
<td class="command">run -p scriptname</td>
<td>runs the profiler on the script, <span class=<br />
"c">scriptname</span>.&nbsp; <span class="c">run -p</span> works on files, not statements.</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://scienceoss.com/debugging-and-optimizing-in-ipython/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Edit your code in IPython</title>
		<link>http://scienceoss.com/editing-code-in-ipython/</link>
		<comments>http://scienceoss.com/editing-code-in-ipython/#comments</comments>
		<pubDate>Sun, 02 Dec 2007 17:31:39 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[IPython]]></category>
		<category><![CDATA[IPython help]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://scienceoss.com/?p=38</guid>
		<description><![CDATA[IPython makes it easy to edit source code, or create new scripts based on a couple of lines in your history, or paste examples from the web. edit script.py Opens script.py in the default editor.&#160; NOTE: upon exit, the script executes edit -x script.py Opens script.py in the default editor.&#160; Upon exit, the script will [...]]]></description>
			<content:encoded><![CDATA[<p>IPython makes it easy to edit source code, or create new scripts based on a couple of lines in your history, or paste examples from the web.<span id="more-38"></span></p>
<table border="0" cellpadding="4" >
<tbody>
<tr>
<td class="command">edit script.py</td>
<td>Opens <span class="c">script.py</span> in the<br />
default editor.&nbsp; NOTE: upon exit, the script executes</td>
</tr>
<tr>
<td class="command">edit -x script.py</td>
<td>Opens <span class="c">script.py</span> in the<br />
default editor.&nbsp; Upon exit, the script will not execute.</td>
</tr>
<tr>
<td class="command">edit 1-3 6</td>
<td>Opens the default editor to edit commands 1, 2, 3,<br />
and 6 in the history</td>
</tr>
<tr>
<td class="command">save apple 1-3, 5</td>
<td>Saves the history commands 1, 2, 3, and 5 in the file apple.py</td>
</tr>
<tr>
<td class="command">cpaste</td>
<td>Tells IPython to expect code pasted from the<br />
clipboard.&nbsp; NOTE: type <span class="c">&#8211;</span> on a line by itself to quit out of <span class="c">cpaste</span> mode.</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://scienceoss.com/editing-code-in-ipython/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>System commands from IPython</title>
		<link>http://scienceoss.com/system-commands-from-ipython/</link>
		<comments>http://scienceoss.com/system-commands-from-ipython/#comments</comments>
		<pubDate>Sun, 02 Dec 2007 17:29:14 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[IPython]]></category>
		<category><![CDATA[IPython help]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://scienceoss.com/?p=37</guid>
		<description><![CDATA[You can make use of your Python skills by interacting with system commands directly for things like file renaming, directory restructuring, or calling any arbitrary system command from within IPython. Here are some ways to do that. ! at the beginning of a line, tells IPython this line is to be sent to the system [...]]]></description>
			<content:encoded><![CDATA[<p>You can make use of your Python skills by interacting with system commands directly for things like file renaming, directory restructuring, or calling any arbitrary system command from within IPython.  Here are some ways to do that.<span id="more-37"></span></p>
<table border="0" cellpadding="4" >
<tbody>
<tr>
<td class="command">!</td>
<td>at the beginning of a line, tells IPython this line is to be sent to the system shell</td>
</tr>
<tr>
<td class="command">!ls</td>
<td>list directory (the magic function, <span class="c">ls</span>, does the same thing)</td>
</tr>
<tr>
<td class="command">patt = &#8216;*.py&#8217;</td>
<td>set up a Python variable, <span class="c">patt</span>, which will be used in the examples below</td>
</tr>
<tr>
<td class="command">!ls -l $patt</td>
<td>look for .py files using the <span class="c">-l</span> format.&nbsp; The <span class="c">$</span> expands<br />
the Python variable to the shell.</td>
</tr>
<tr>
<td class="command">!ls -l ${patt+c}</td>
<td>adds a c to the end of patt to make ls look for <span class="c">.pyc</span> files.&nbsp; <span class="c">{}</span> indicates a Python expression</td>
</tr>
<tr>
<td class="command">alias</td>
<td>shows defined aliases, like <span class= "c">ldir</span> or <span class="c">ll</span></td>
</tr>
<tr>
<td class="command">alias pr echo You Said: %s</td>
<td>define an alias called <span class="c">pr</span></td>
</tr>
<tr>
<td class="command">pr HELLO</td>
<td>prints out &#8220;<span class="c">You Said HELLO</span>&#8221; (executes the alias)</td>
</tr>
<tr>
<td class="command">unalias pr</td>
<td>remove the alias <span class="c">pr</span></td>
</tr>
</tbody>
</table>
<p><strong>Note:</strong> The magic command, ls, can also be used to find .py files with the command ls *.py.&nbsp; However, more advanced usage, like passing Python variables and expressions or using options of the ls command (!ls -lha for example, to list the details of all files, including hidden ones, with human-readable sizes ) need to be done with the system command. The magic command is actually an alias for !ls -F.&nbsp; Using the system call form is the more general case, and can be used for any system calls.</p>
<p style="margin-bottom: 0in"></p>
<p style="margin-bottom: 0in">Define a function to be used in the examples below:</p>
<pre class="prettyprint">
def go(patt):  <span class="prettyprint">
    !ls -l $patt</span>   
</pre>
<p></p>
<table border="0" cellpadding="4" >
<tbody>
<tr>
<td class="command">go(&#8216;*.py&#8217;)</td>
<td>looks for .py files using the <span class="c">go</span>() function defined above</td>
</tr>
<tr>
<td class="command">x = !ls</td>
<td>saves a list of the results of the system call to <span class="c">ls</span></td>
</tr>
<tr>
<td class="command">len(x)</td>
<td>how many items were in the directory (where <span class="c">x = !ls</span> as above)</td>
</tr>
<tr>
<td class="command">x.s</td>
<td>displays the contents as a long string</td>
</tr>
<tr>
<td class="command">x.l</td>
<td>displays as a list</td>
</tr>
<tr>
<td class="command">x.n</td>
<td>display with newlines</td>
</tr>
<tr>
<td class="command">x = !ls *.py | sort</td>
<td>a sorted list of items ending with .py in the<br />
directory</td>
</tr>
</tbody>
</table>
<p style="margin-bottom: 0in">Note: the list returned by a system call is not a standard Python list.&nbsp; Rather, it is a list of type <span class="c">IPython.genutils.SList</span> which has the <span class="c">.s</span>, <span class="c">.l</span>, and other useful methods.&nbsp; Check out what it can do with <span class="c">x.</span>[tab] (see introspection section, above).</p>
]]></content:encoded>
			<wfw:commentRss>http://scienceoss.com/system-commands-from-ipython/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shortcuts in IPython</title>
		<link>http://scienceoss.com/shortcuts-in-ipython/</link>
		<comments>http://scienceoss.com/shortcuts-in-ipython/#comments</comments>
		<pubDate>Sun, 02 Dec 2007 17:25:44 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[IPython]]></category>
		<category><![CDATA[IPython help]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://scienceoss.com/?p=36</guid>
		<description><![CDATA[For the pathologically lazy, there are some shortcuts in IPython to save you from typing often-used commands. p short for print page prints long variables one page at a time demo1 3,4 function call to demo1(): don&#8217;t have to use parentheses ,demo1 a,b function call to demo1(): send arguments as strings &#8216;a&#8217; and &#8216;b&#8217; /demo2 [...]]]></description>
			<content:encoded><![CDATA[<p>For the pathologically lazy, there are some shortcuts in IPython to save you from typing often-used commands.<br />
<span id="more-36"></span></p>
<table border="0" cellpadding="4" >
<tbody>
<tr>
<td class="command">p</td>
<td>short for <span class="c">print</span></td>
</tr>
<tr>
<td class="command">page</td>
<td>prints long variables one page at a time</td>
</tr>
<tr>
<td class="command">demo1 3,4</td>
<td>function call to <span class="c">demo1()</span>: don&#8217;t have to use parentheses</td>
</tr>
<tr>
<td class="command">,demo1 a,b</td>
<td>function call to <span class="c">demo1()</span>: send arguments as strings <span class="c">&#8216;a&#8217;</span> and <span class="c">&#8216;b&#8217;</span></td>
</tr>
<tr>
<td class="command">/demo2</td>
<td>function call to <span class="c">demo2()</span>, a function with no input arguments</td>
</tr>
<tr>
<td class="command">xyz(3,4);</td>
<td>semicolon suppresses output from <span class="c">xyz()</span>&#8216;s return statement</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://scienceoss.com/shortcuts-in-ipython/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>History: keep track of your work in IPython</title>
		<link>http://scienceoss.com/keeping-track-of-your-work-in-ipython/</link>
		<comments>http://scienceoss.com/keeping-track-of-your-work-in-ipython/#comments</comments>
		<pubDate>Sun, 02 Dec 2007 17:23:10 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[IPython]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://scienceoss.com/?p=35</guid>
		<description><![CDATA[This post shows the different ways of keeping track of your work in IPython: the command history, saving the history (or parts of the history to file) for later use, and storing variables so you don&#8217;t have to create them next time you use IPython. History Note: In the history, you may see _ip.magic().&#160; This [...]]]></description>
			<content:encoded><![CDATA[<p>This post shows the different ways of keeping track of your work in IPython: the command history, saving the history (or parts of the history to file) for later use, and storing variables so you don&#8217;t have to create them next time you use IPython.<span id="more-35"></span></p>
<h2>History</h2>
<p style="margin-bottom: 0in; font-style: normal">
<strong>Note:</strong> In the history, you may see _ip.magic().&nbsp; This is the wrapper used to run magic commands</p>
<p style="margin-bottom: 0in; font-style: normal">&nbsp;</p>
<table border="0" cellpadding="4" >
<tbody>
<tr>
<td class="command">In[5]:</td>
<td>The prompt shows the number of the command in the history</td>
</tr>
<tr>
<td class="command">In[3]</td>
<td>The list, <span class="c">In</span>, contains the history.&nbsp; So this command shows the third item in the history&nbsp; (item 0 is a newline)&nbsp;</td>
</tr>
<tr>
<td class="command">Out.keys()</td>
<td>The output cache, <span class="c">Out</span>, is a dictionary.&nbsp; Use this to see the keys in the output cache</td>
</tr>
<tr>
<td class="command">_i</td>
<td>show the last command</td>
</tr>
<tr>
<td class="command">_ii</td>
<td>show the second-to-last command</td>
</tr>
<tr>
<td class="command">_iii</td>
<td>show the third-to-last command (and so<br />
on)</td>
</tr>
<tr>
<td class="command">_i10</td>
<td>show the tenth command in history (same as <span class="c">In[10]</span>)</td>
</tr>
<tr>
<td class="command">exec _i</td>
<td>execute the last command</td>
</tr>
<tr>
<td class="command">exec _i4</td>
<td>execute the fourth command in the history</td>
</tr>
<tr>
<td class="command">hist</td>
<td>display the last 20 or so commands</td>
</tr>
<tr>
<td class="command">hist 100</td>
<td>display the last 100 commands</td>
</tr>
<tr>
<td class="command">hist 3 10</td>
<td>display commands 3 through 10 in the<br />
history</td>
</tr>
<tr>
<td class="command">hist -r</td>
<td>hide the wrappers around magic commands</td>
</tr>
<tr>
<td class="command">macro mac 1-4 7</td>
<td>create a macro called mac out of lines 1, 2, 3, 4, and 7 of the history</td>
</tr>
<tr>
<td class="command">mac</td>
<td>runs the macro called <span class="c">mac</span></td>
</tr>
<tr>
<td class="command">print mac</td>
<td>prints the commands in <span class=<br />
"c">mac</span></td>
</tr>
<tr>
<td class="command">store mac</td>
<td>stores the macro in the profile, it will be available next time you start IPython</td>
</tr>
</tbody>
</table>
<table border="0" cellpadding="4" >
<tbody>
<tr>
<td class="command">store x</td>
<td>store <span class="c">x</span> in the profile. It will be loaded next time you start IPython.</td>
</tr>
<tr>
<td class="command">store x &gt; /tmp/a.txt</td>
<td>store <span class="c">x</span> in the file, <span class="c">a.txt</span></td>
</tr>
<tr>
<td class="command">store -r</td>
<td>restore into the workspace the variables that have been stored. Overwrites exisiting variables in workspace.</td>
</tr>
<tr>
<td class="command">store -d x</td>
<td>delete just <span class="c">x</span> from<br />
storage</td>
</tr>
<tr>
<td class="command">store -z</td>
<td>remove ALL variables from storage</td>
</tr>
</tbody>
</table>
<p></p>
<p style="margin-bottom: 0in"></p>
<h2>Logging your session for later use</h2>
<table border="0" cellpadding="4" >
<tbody>
<tr>
<td class="command">logstate</td>
<td>show state of the logger (on or off)</td>
</tr>
<tr>
<td class="command">logstart</td>
<td>start logging (default log file is <span class="c">ipython_log.py</span>, in the present working directory</td>
</tr>
<tr>
<td class="command">logstart filename</td>
<td>store history up to this point, and continue logging history, in <span class="c">filename</span></td>
</tr>
<tr>
<td class="command">logstart -r filename</td>
<td>same as above, but use the raw input: don&#8217;t put the <span class="c">_ip.magic()</span> wrapper around magic commands</td>
</tr>
<tr>
<td class="command">logon</td>
<td>start logging after stopping</td>
</tr>
<tr>
<td class="command">logoff</td>
<td>stop logging after starting</td>
</tr>
<tr>
<td class="command">runlog log1 log2</td>
<td>run the log file <span class="c">log1</span>, then run the log file <span class="c">log2</span> (this executes the logged histories)</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://scienceoss.com/keeping-track-of-your-work-in-ipython/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Managing variables in IPython</title>
		<link>http://scienceoss.com/managing-variables-in-ipython/</link>
		<comments>http://scienceoss.com/managing-variables-in-ipython/#comments</comments>
		<pubDate>Sun, 02 Dec 2007 17:18:02 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[IPython]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://scienceoss.com/?p=34</guid>
		<description><![CDATA[After working in IPython for a while, sometimes you&#8217;d like to use a variable you created way back at the beginning, but you don&#8217;t remember exactly what it was called. Here are some useful commands for working with variables in IPython. who show contents of workspace who int show integers in workspace whos show details [...]]]></description>
			<content:encoded><![CDATA[<p>After working in IPython for a while, sometimes you&#8217;d like to use a variable you created way back at the beginning, but you don&#8217;t remember exactly what it was called.  Here are some useful commands for working with variables in IPython.<span id="more-34"></span></p>
<table border="0" cellpadding="4" >
<tbody>
<tr>
<td class="command">who</td>
<td>show contents of workspace</td>
</tr>
<tr>
<td class="command">who int</td>
<td>show integers in workspace</td>
</tr>
<tr>
<td class="command">whos</td>
<td>show details of workspace contents</td>
</tr>
<tr>
<td class="command">whos int</td>
<td>show details of integers in workspace</td>
</tr>
<tr>
<td class="command">psearch msg*</td>
<td>search for objects in the workspace starting with <span class="c">msg</span></td>
</tr>
<tr>
<td class="command">psearch msg* int</td>
<td>restrict search to just integers</td>
</tr>
<tr>
<td class="command">reset</td>
<td>delete all variables from workspace</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://scienceoss.com/managing-variables-in-ipython/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Running a program in IPython</title>
		<link>http://scienceoss.com/running-a-program-in-ipython/</link>
		<comments>http://scienceoss.com/running-a-program-in-ipython/#comments</comments>
		<pubDate>Sun, 02 Dec 2007 17:16:05 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[IPython]]></category>
		<category><![CDATA[IPython help]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://scienceoss.com/?p=33</guid>
		<description><![CDATA[Running programs or scripts in IPython is easy, and here are the commands to use. run filename.py runs the program filename.py found in the present working directory run python/filename.py runs the program filename.py found in the python directory under the present working directory run -p filename profile the script, filename run -d filename run the [...]]]></description>
			<content:encoded><![CDATA[<p>Running programs or scripts in IPython is easy, and here are the commands to use.<span id="more-33"></span></p>
<table border="0" cellpadding="4" >
<tbody>
<tr>
<td class="command">run filename.py</td>
<td>runs the program <span class=<br />
"c">filename.py</span> found in the present working directory</td>
</tr>
<tr>
<td class="command">run python/filename.py</td>
<td>runs the program <span class=<br />
"c">filename.py</span> found in the <span class="c">python</span> directory under the present working directory</td>
</tr>
<tr>
<td class="command">run -p filename</td>
<td>profile the script, <span class=<br />
"c">filename</span></td>
</tr>
<tr>
<td class="command">run -d filename</td>
<td>run the script through the Python debugger, <span class="c">pdb</span></td>
</tr>
<tr>
<td class="command">run?</td>
<td>show help for run . . . many useful options</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://scienceoss.com/running-a-program-in-ipython/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Directory navigation in IPython</title>
		<link>http://scienceoss.com/directory-navigation-in-ipython/</link>
		<comments>http://scienceoss.com/directory-navigation-in-ipython/#comments</comments>
		<pubDate>Sun, 02 Dec 2007 17:15:21 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[IPython]]></category>
		<category><![CDATA[directory navigation]]></category>
		<category><![CDATA[IPython help]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://scienceoss.com/?p=32</guid>
		<description><![CDATA[A reference table of commands to use when navigating directories in IPython. pwd display the present working directory ls list the contents of the present working directory cd /tmp move to the /tmp directory cd .. move up one directory cd - move to the last directory visited bookmark mydir save the current directory as [...]]]></description>
			<content:encoded><![CDATA[<p>A reference table of commands to use when navigating directories in IPython.<span id="more-32"></span></p>
<table border="0" cellpadding="4" >
<tbody>
<tr>
<td class="command">pwd</td>
<td>display the present working directory</td>
</tr>
<tr>
<td class="command">ls</td>
<td>list the contents of the present working<br />
directory</td>
</tr>
<tr>
<td class="command">cd /tmp</td>
<td>move to the <span class="c">/tmp</span><br />
directory</td>
</tr>
<tr>
<td class="command">cd ..</td>
<td>move up one directory</td>
</tr>
<tr>
<td class="command">cd -</td>
<td>move to the last directory visited</td>
</tr>
<tr>
<td class="command">bookmark mydir</td>
<td>save the current directory as <span class= "c">mydir</span></td>
</tr>
<tr>
<td class="command">bookmark mydir ../python</td>
<td>bookmarks the directory <span class=<br />
"c">../python</span> (up one directory, then down into <span class= "c">python</span>) as <span class="c">mydir</span></td>
</tr>
<tr>
<td class="command">cd mydir</td>
<td>change to the directory saved in the bookmark <span class="c">mydir</span></td>
</tr>
<tr>
<td class="command">dhist</td>
<td>view a history of the directories you&#8217;ve been<br />
to</td>
</tr>
<tr>
<td class="command">cd -2</td>
<td>change to the directory listed in position 2 in the directory history</td>
</tr>
<tr>
<td class="command">pushd /usr/lib</td>
<td>push <span class="c">/usr/lib</span> onto the directory stack</td>
</tr>
<tr>
<td class="command">dirs</td>
<td>show directories in the directory stack</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://scienceoss.com/directory-navigation-in-ipython/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

