<?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 help</title>
	<atom:link href="http://scienceoss.com/tags/ipython-help/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.2</generator>
		<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>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>
		<item>
		<title>Getting help in IPython</title>
		<link>http://scienceoss.com/getting-help-in-ipython/</link>
		<comments>http://scienceoss.com/getting-help-in-ipython/#comments</comments>
		<pubDate>Sun, 02 Dec 2007 17:04:08 +0000</pubDate>
		<dc:creator>ryan</dc:creator>
				<category><![CDATA[IPython]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[IPython help]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://scienceoss.com/?p=31</guid>
		<description><![CDATA[IPython has an in-depth integrated help system. You can get help on IPython&#8217;s magic functions, view documentation from a single function, check out syntax-highlighted source code, or enter the Python interactive help system. Here&#8217;s a list of the commands to use. lsmagic lists the magic commands ? (at the end of a function or variable) [...]]]></description>
			<content:encoded><![CDATA[<p>IPython has an in-depth integrated help system.  You can get help on IPython&#8217;s magic functions, view documentation from a single function, check out syntax-highlighted source code, or enter the Python interactive help system.  Here&#8217;s a list of the commands to use.<span id="more-31"></span></p>
<table border="0" cellpadding="4" >
<tbody>
<tr>
<td class="command">lsmagic</td>
<td>lists the magic commands</td>
</tr>
<tr>
<td class="command">?</td>
<td>(at the end of a function or variable) show help</td>
</tr>
<tr>
<td class="command">??</td>
<td>(at the end of a function or object) show detailed help; often includes source code</td>
</tr>
<tr>
<td class="command">help(sys)</td>
<td>online documentation for the <span class="c">sys</span> module (sys must be imported first)</td>
</tr>
<tr>
<td class="command">help(&#8216;for&#8217;)</td>
<td>online doc for the <span class="c">for</span><br />
keyword</td>
</tr>
<tr>
<td class="command">help()</td>
<td>enters the help system</td>
</tr>
<tr>
<td class="command">topics</td>
<td>(at the help prompt) lists help topics.&nbsp; Type<br />
one to view it.</td>
</tr>
<tr>
<td class="command">q</td>
<td>(at the help prompt) Exit the help<br />
system.</td>
</tr>
</tbody>
</table>
<p>&nbsp;<br />
Import the <span class="mainbody">re</span> module (regular expression module) as an example for the commands below:</p>
<pre class="prettyprint">
import re
</pre>
<table border="0" cellpadding="4" >
<tbody>
<tr>
<td class="command">pdef re.match</td>
<td>just the initialization expression for the <span class="c">re.match</span> function</td>
</tr>
<tr>
<td class="command">pdoc re.match</td>
<td>just the help text for <span class="c">re.match</span></td>
</tr>
<tr>
<td class="command">pinfo re.match</td>
<td>same as using <span class="c">re.match?</span><br />
(shows help)</td>
</tr>
<tr>
<td class="command">psource re.match</td>
<td>same as using <span class="c">re.match??</span><br />
(shows detailed help)</td>
</tr>
<tr>
<td class="command">pfile re.match</td>
<td>shows the contents of the file where the function<br />
is defined</td>
</tr>
<tr>
<td class="command">pycat scriptName</td>
<td>displays the file, <span class= "c">scriptName</span>, in syntax-highlighted text</td>
</tr>
<tr>
<td class="command">edit -x re.match</td>
<td>opens the source file for <span class= "c">re.match</span> in default editor</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://scienceoss.com/getting-help-in-ipython/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

