<?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>Dragly &#187; Python</title>
	<atom:link href="http://dragly.org/category/programming/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://dragly.org</link>
	<description>It was about time I started writing my own tutorials to share some of the knowledge I&#039;ve picked up from around.</description>
	<lastBuildDate>Mon, 14 May 2012 22:32:56 +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>Adjusting to the new version of Pylab and Mayavi on Ubuntu 12.04</title>
		<link>http://dragly.org/2012/05/15/adjusting-to-the-new-version-of-pylab-and-mayavi-on-ubuntu-12-04/</link>
		<comments>http://dragly.org/2012/05/15/adjusting-to-the-new-version-of-pylab-and-mayavi-on-ubuntu-12-04/#comments</comments>
		<pubDate>Mon, 14 May 2012 22:32:27 +0000</pubDate>
		<dc:creator>Svenn-Arne Dragly</dc:creator>
				<category><![CDATA[Mindseye]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[distribution]]></category>
		<category><![CDATA[enthought]]></category>
		<category><![CDATA[epd]]></category>
		<category><![CDATA[ipython]]></category>
		<category><![CDATA[mayavi]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[threading]]></category>
		<category><![CDATA[wthread]]></category>

		<guid isPermaLink="false">http://dragly.org/?p=754</guid>
		<description><![CDATA[It seems the IPython and Pylab packages has also been updated in 12.04 and thus removing the old ipython -wthread flag that would ensure Mayavi plots to be run in a separate thread. Running with the flag causes this error &#8230; <a href="http://dragly.org/2012/05/15/adjusting-to-the-new-version-of-pylab-and-mayavi-on-ubuntu-12-04/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It seems the IPython and Pylab packages has also been updated in 12.04 and thus removing the old ipython -wthread flag that would ensure Mayavi plots to be run in a separate thread. Running with the flag causes this error to show up:</p>
<pre>[TerminalIPythonApp] Unrecognized flag: '-wthread'</pre>
<p>Without this flag, the Mayavi plots lock up the UI and hangs. If you want to get the possibility back to rotate and play around with the plots, just start IPython the following way from now on:</p>
<pre>
ipython --pylab=qt
</pre>
<p>This will launch IPython with the Qt backend and threading. Using only &#8211;pylab does not include threading. For easy and quick access, add the following to a file named .bashrc in your home folder:</p>
<pre>
alias pylab='ipython --pylab=qt'
</pre>
<p>From now on you can launch IPython just by typing</p>
<pre>
pylab
</pre>
<p>in a terminal.</p>
]]></content:encoded>
			<wfw:commentRss>http://dragly.org/2012/05/15/adjusting-to-the-new-version-of-pylab-and-mayavi-on-ubuntu-12-04/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the same script on installs with different EPD versions</title>
		<link>http://dragly.org/2012/05/15/using-the-same-script-on-installs-with-different-epd-versions/</link>
		<comments>http://dragly.org/2012/05/15/using-the-same-script-on-installs-with-different-epd-versions/#comments</comments>
		<pubDate>Mon, 14 May 2012 22:20:51 +0000</pubDate>
		<dc:creator>Svenn-Arne Dragly</dc:creator>
				<category><![CDATA[Mindseye]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[distribution]]></category>
		<category><![CDATA[enthought]]></category>
		<category><![CDATA[enthought python distribution]]></category>
		<category><![CDATA[epd]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[import error]]></category>
		<category><![CDATA[importerror]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://dragly.org/?p=751</guid>
		<description><![CDATA[In the newest version of Enthought&#8217;s Python Distribution (EPD) on Ubuntu, the plotting package has been moved from enthought.mayavi.mlab to the shorter and more general mayavi.mlab. This does however mean that if you, like me, need to work with different &#8230; <a href="http://dragly.org/2012/05/15/using-the-same-script-on-installs-with-different-epd-versions/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In the newest version of Enthought&#8217;s Python Distribution (EPD) on Ubuntu, the plotting package has been moved from enthought.mayavi.mlab to the shorter and more general mayavi.mlab. This does however mean that if you, like me, need to work with different versions of EPD on multiple systems, will experience the following error from time to time:</p>
<pre>ImportError: No module named enthought.mayavi.mlab</pre>
<p>Now, to avoid switching the import statement every time you switch systems, you can make Python check if one of the versions is installed during import. If it is not, we&#8217;ll tell it to try the other. This is done in this simple command:</p>
<pre class="brush:py">try:
    from enthought.mayavi.mlab import *
except ImportError:
    from mayavi.mlab import *</pre>
<p>Just replace any other similar import statements the same way and your code should once again be working across all your installations.</p>
]]></content:encoded>
			<wfw:commentRss>http://dragly.org/2012/05/15/using-the-same-script-on-installs-with-different-epd-versions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python deleted my vector values</title>
		<link>http://dragly.org/2010/02/15/python-deleted-my-vector-values/</link>
		<comments>http://dragly.org/2010/02/15/python-deleted-my-vector-values/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 16:23:54 +0000</pubDate>
		<dc:creator>Svenn-Arne Dragly</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://svenni.dragly.com/v7/?p=191</guid>
		<description><![CDATA[Sometimes scripting languages can be a real annoyance. Why? Because when you get as much help as you do with for instance Python, you also lose a lot of control. Being used to scripting languages like PHP, I made the &#8230; <a href="http://dragly.org/2010/02/15/python-deleted-my-vector-values/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sometimes scripting languages can be a real annoyance. Why? Because when you get as much help as you do with for instance Python, you also lose a lot of control.</p>
<p>Being used to scripting languages like PHP, I made the funny mistake today of initializing a set of arrays like:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">a = v = r = zeros<span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>n,<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>,<span style="color: #008000;">float</span><span style="color: black;">&#41;</span></pre></div></div>

<p>This seemed like a really good idea, saving me from typing two extra lines(!). As the sucker I am for short code I was happy with my newfound shortcut. What I didn&#8217;t realize is that Python, in comparison to PHP, treats assignments like these as pointers instead of variables.</p>
<p>I believed this would create three arrays with a lot of zeros in two dimensions as I would expect from PHP, but the result was that I instead created one array with loads of zeros in two dimensions, with three pointers <strong>a</strong>, <strong>v</strong> and <strong>r</strong> all pointing to the same array.</p>
<p>When I then started setting the values for each of these arrays using Euler&#8217;s method, the result was that I got a lot of nonsense in what I thought was three separate arrays.</p>
<p>As a reminder to myself and everyone else out there; Python is not PHP. If you want to initialize three arrays like this in Python, you&#8217;ll have to stick to  the long version:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">a = zeros<span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>n,<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>,<span style="color: #008000;">float</span><span style="color: black;">&#41;</span>
r = zeros<span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>n,<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>,<span style="color: #008000;">float</span><span style="color: black;">&#41;</span>
v = zeros<span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>n,<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>,<span style="color: #008000;">float</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Or, you could at least save yourself from having to edit each assignment if you ever need to change the code by writing:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">a = zeros<span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>n,<span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>,<span style="color: #008000;">float</span><span style="color: black;">&#41;</span>
r = a.<span style="color: #dc143c;">copy</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
v = a.<span style="color: #dc143c;">copy</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://dragly.org/2010/02/15/python-deleted-my-vector-values/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

