<?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>Incredible Vehicle &#187; python</title>
	<atom:link href="http://incrediblevehicle.com/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>https://incrediblevehicle.com</link>
	<description>(It&#039;s a blog.)</description>
	<lastBuildDate>Fri, 27 Apr 2012 03:50:37 +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>In search of productivity</title>
		<link>https://incrediblevehicle.com/2012/02/18/in-search-of-productivity/</link>
		<comments>https://incrediblevehicle.com/2012/02/18/in-search-of-productivity/#comments</comments>
		<pubDate>Sat, 18 Feb 2012 23:20:11 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://incrediblevehicle.com/?p=1055</guid>
		<description><![CDATA[Once upon a time, I started to learn programming in C++. It turns out that it&#8217;s hard (for some value of &#8220;hard&#8221;) to do a lot of basic things in C++. As a budding programmer, I spent more time struggling to make myself understood to the compiler than writing code. When I was introduced to [...]]]></description>
			<content:encoded><![CDATA[<p>Once upon a time, I started to learn programming in C++. It turns out that it&#8217;s hard (for some value of &#8220;hard&#8221;) to do a lot of basic things in C++. As a budding programmer, I spent more time struggling to make myself understood to the compiler than writing code.</p>

<p>When I was introduced to Python, suddenly programming was fun again. It was hard to imagine going back to anything like C++ when I could become so productive so quickly with Python.</p>

<p>I held to this view for a very, very long time. I appreciated how languages like C++ or Java would be useful for writing &#8220;serious&#8221; applications, but I didn&#8217;t write that stuff. That was for other people.</p>

<p>In the last year or so, I&#8217;ve gradually come to believe that a strong type-checking system AND a high-productivity language ought not and are not mutually exclusive. The corollary is that I will consider carefully before I use a scripting language for anything more than a thousand or so lines.</p>

<p><span id="more-1055"></span></p>

<h3>The first sign of trouble</h3>

<p>The first time I ran into serious trouble with a scripting language was a few years ago (yikes). I wrote a script in Python which would monitor some servers for updated software and kick off a job when they were updated. It was less than 1000 lines, but despite knowing better, I did a poor job keeping it clean. And because it was such a mess, of course I had no tests.</p>

<p>Without unit tests, I had to test it manually. The cycle was something like: write a bunch of code, and run the whole dang script. This was time-consuming and error-prone. I&#8217;d miss things. Basic things. The script itself wasn&#8217;t mission critical but I found these bugs and the script itself personally embarrassing; I knew better, and I knew I knew better.</p>

<p>Still, I was otherwise quite productive in Python. Around the same time, using the Django framework, I wrote a server which slurped XML-formatted test results and allowed the user to view results grouped by various properties. It was very fast to write, and I could hardly imagine doing it in C++ or Java.</p>

<p>I had three experiences in the last year or two which rearranged my prejudices.</p>

<h3>JavaScript and the Closure Compiler</h3>

<p>The first was working in JavaScript land, with the <a href="http://code.google.com/closure/compiler/">Closure Compiler</a>. JavaScript was far less restrictive and, in my opinion, more expressive than Java. The compiler caught some of my dumb mistakes and I grudgingly came to value it. However, it didn&#8217;t catch all of my mistakes and the ones that it did not catch were sometimes difficult to track down.</p>

<p>The lesson I learned was that even the slightest type-checking can really help save you from yourself. It also makes refactoring (and thus maintenance) easier; adding or removing a parameter, or passing in the wrong type can be difficult to debug in a language like JavaScript.</p>

<h3>Java</h3>

<p>The second was working in Java land. I wrote a framework which would test a remote API. I had to do a lot of fighting with the language, with a lot of boilerplate and book-keeping. I missed closures and first class functions dearly; contrary to what I thought at first, Java does have a very limited form of closures, in the form of anonymous inner classes. The lengths I had to go to get certain pieces working was comical; at one point, I wrote a <a href="http://incrediblevehicle.com/2011/07/25/java-me/">FactoryFactory</a>. I&#8217;m not kidding! And I&#8217;m not proud of it, but the language and API I was using drove me to it.</p>

<p>However, up to this point in my career, I don&#8217;t think I&#8217;d spent as much time with a decent IDE on an extended project. Several aspects were revelatory. I&#8217;ll mention two.</p>

<p>1) The type system gave me substantially more confidence that I was doing the right thing most of the time. I spent more time fixing incorrect assumptions about the API, adding error-recovery, or simply writing code than chasing down basic mistakes. I do that in any language, but the difference here was that the IDE and language eliminated an entire class of mistakes <em>as I introduced them</em>. By the time I ran my program, I had substantially more confidence about its correctness than I ever did in Python.</p>

<p>2) If you haven&#8217;t yet, read Martin Fowler&#8217;s <a href="http://www.amazon.com/gp/product/0201485672/ref=as_li_ss_tl?ie=UTF8&amp;tag=incredvehicl-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0201485672">Refactoring</a>. The short version is that there are a set of highly mechanical techniques you can use to facilitate refactoring. Furthermore, many Java IDEs support many of these operations. Even something as basic as renaming method calls or variables within a specific context is massively more helpful than dumb S&amp;R.</p>

<h3>Lest I seem insane</h3>

<p>Despite all that, I still wouldn&#8217;t program in Java again by choice. I want closures. I want first class functions. I want built-in higher order functions, for that matter. I want syntax and/or a syntactic paradigm (think variables or methods like fooByBarWithBazAsQuux) that&#8217;s substantially less verbose.</p>

<p>It&#8217;s the difference between</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">numbers = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">2</span>, <span style="color:#006666;">3</span>, <span style="color:#006666;">4</span>, <span style="color:#006666;">5</span>, <span style="color:#006666;">6</span><span style="color:#006600; font-weight:bold;">&#93;</span>
evens = numbers.<span style="color:#CC0066; font-weight:bold;">select</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span> x <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006666;">2</span> == <span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>


<p>and</p>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// I'm sure this is still invalid for many reasons.</span>
ArrayList<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> intList <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">4</span>, <span style="color: #cc66cc;">5</span>, <span style="color: #cc66cc;">6</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
ArrayList<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span> evenIntsList <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayList<span style="color: #339933;">&lt;</span>Integer<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Integer</span> i <span style="color: #339933;">:</span> intList<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    evenIntsList.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<p>That? That up there? It hurts me inside. The compiler makes it harder for you to screw it up, but you still have to do the whole song and dance every. Single. Time. You spend ~6 lines on an operation which, in the grand scheme of your program, ought to be small and trivial.</p>

<h3>Python</h3>

<p>Speaking of Python, I started relatively recently on refactoring a set of Python scripts responsible for kicking off tests. Nobody owned these scripts and consequently they languished as multiple people had patched or hacked on them to fix bugs or add features. The scripts were a mess.</p>

<p>Furthermore, there are few thousand lines of these scripts, plus thousands of lines more in the form of libraries which the scripts use. There were and are tests, but obviously nobody ran them because they were all broken.</p>

<p>After having spent so much time in the Land of Type-checking, reality came rushing back. It scary to make changes without having any confidence that they were correct. I wrote tests to find basic mistakes which would not manifest until runtime.</p>

<p>I would say that this was the biggest shock and what did the most to change my views. A scripting language is very good for getting something running quickly, but in terms of refactoring and maintenance, it took two or three times as long as I thought it ought to.</p>

<h3>A word about tests</h3>

<p>You could make a strong case that the scenario above— writing tests to the point of boredom— is Working As Intended. I am strongly sympathetic to this idea.</p>

<p>You ought to write unit tests with good coverage no matter the language. Tools like <a href="https://github.com/gfxmonk/autonose">autonose</a> allow you to get feedback from those tests rather quickly. This workflow arguably gives you faster, more comprehensive feedback than one with just a compiler and manually run unit tests.</p>

<p>One hitch is that getting a good error message from a unit test requires an amount of diligence multiplied by the number of unit tests. A compiler does only catch a small subset of the problems a unit test would, but any decent one ought to catch them more reliably and precisely.</p>

<p>Anyway, I haven&#8217;t delved too much into larger-scale projects which are based on scripting languages, but my guess is that their approach is similar to this. Write testable code. Use frameworks which make it easy to write tests (with a nice DSL, flexible mocking, or what have you). Use frameworks which make it easy to run tests (such as speed and parallelism). Minimize the inherent friction and you&#8217;ll get something richer than a compiler alone would offer you.</p>

<h3>The answer?</h3>

<p>I&#8217;m still writing tests in Java. I&#8217;m still refactoring Python scripts. For obvious reasons it would be silly to introduce a new technology into an existing stack chiefly or even partially for my own personal satisfaction. Rewriting is a dubious proposition anyway, one that must be considered very carefully. So for practical reasons, the situation won&#8217;t change.</p>

<p>Even so, I still want to have some go-to language. What could I use for a new project, personal or otherwise which would have good odds of making me happy?</p>

<p>C++ is not memory safe. C is simpler than C++ but is also memory unsafe and has more trade-offs. In both C and C++, it can be very difficult to write basic functionality.</p>

<p>Java is memory safe and has a rich set of libraries, but as I&#8217;ve mentioned, I&#8217;m not interested.</p>

<p>So what&#8217;s the answer? What language or technology do I feel is most promising, offering a combination of strong typing and high productivity? I have one prospect, or even two. But I&#8217;ll save those for the next post.</p>
]]></content:encoded>
			<wfw:commentRss>https://incrediblevehicle.com/2012/02/18/in-search-of-productivity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python, Python, Python</title>
		<link>https://incrediblevehicle.com/2011/08/31/python-python-python/</link>
		<comments>https://incrediblevehicle.com/2011/08/31/python-python-python/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 02:46:34 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://incrediblevehicle.com/?p=978</guid>
		<description><![CDATA[Oh, god. I still have a bunch of rant left in me. So here we go, Internet: yet another angry rant to add to the pile. Sometimes, in the course of one&#8217;s life, one is left with a one-off task. In this case, I needed to call a binary a whole lot of times, and [...]]]></description>
			<content:encoded><![CDATA[<p>Oh, god. I still have a bunch of rant left in me. So here we go, Internet: yet another angry rant to add to the pile.</p>

<p>Sometimes, in the course of one&#8217;s life, one is left with a one-off task. In this case, I needed to call a binary a whole lot of times, and do something with the output each time. The details aren&#8217;t important; I just needed to write a wrapper script for this binary, do a modest amount of processing on it, and then output the result to a file. This is a pretty common task, one to which the command line in general and *nix in particular is well-suited.</p>

<p>Now, for various reasons, I prefer not to do this via shell scripts. I don&#8217;t have a hard and fast rule for when or why. Unless you routinely write shell scripts (I don&#8217;t), you&#8217;ll inevitably spend a bunch of time looking stuff up that you looked up, oh, six months ago. Or at least I do. I don&#8217;t enjoy it, so if I can&#8217;t do it with a few commands, maybe one loop or so, then I prefer to use a scripting language. I have the advantage of better/clearer failure modes and simpler syntax and I feel like I&#8217;m learning something more powerful and more widely applicable in the process.</p>

<p><span id="more-978"></span></p>

<p>One of my &#8220;favorite&#8221; things to forget and look up again is the difference between <code>[[ ]]</code> and <code>[ ]</code> in tests. Another one is how you loop over a file or output from a command (<code>while read line; do bar --baz $line; done &lt;foo</code> and <code>foo | while read line; do bar $line; done</code>, respectively).</p>

<p>If you have no trouble remembering this stuff or you write scripts often enough, I suppose this is moot. There was a time when I was scripting enough that I didn&#8217;t have to look all this stuff up every time, but that time is past. YMMV and all that.</p>

<p>Anyway, the point is that I probably could&#8217;ve done this with something like this (which is simplified somewhat):</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">ARGS</span>=<span style="color: #ff0000;">&quot;--bar=baz&quot;</span>
<span style="color: #007800;">CMD</span>=<span style="color: #ff0000;">&quot;~/bin/foo&quot;</span>
<span style="color: #007800;">KEY</span>=<span style="color: #ff0000;">&quot;quux&quot;</span>
<span style="color: #007800;">MIN</span>=<span style="color: #000000;">0</span>
<span style="color: #007800;">MAX</span>=<span style="color: #000000;">10000</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">for</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">seq</span> <span style="color: #000000;">0</span> <span style="color: #000000;">1000</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> num <span style="color: #000000; font-weight: bold;">do</span>;
  <span style="color: #007800;">$CMD</span> <span style="color: #007800;">$num</span> <span style="color: #007800;">$ARGS</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> line;
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #c20cb9; font-weight: bold;">egrep</span> <span style="color: #660033;">-q</span> <span style="color: #007800;">$KEY</span> <span style="color: #000000; font-weight: bold;">&lt;&lt;&lt;</span><span style="color: #007800;">$line</span>; <span style="color: #000000; font-weight: bold;">then</span>
      <span style="color: #007800;">value</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">egrep</span> <span style="color: #660033;">-o</span> <span style="color: #ff0000;">'[1-9]+$'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$num</span>,<span style="color: #007800;">$value</span>&quot;</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
  <span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>


<p>I&#8217;m sure I have a bajillion bugs in there. For example, I am not at all confident about the outer <code>for</code> loop syntax. And while it was easy to write, I&#8217;m not doing anything with command line args, doing any error handling, or anything like that. (On the other other hand, I uh underestimated how easy this was. That&#8217;s partially why I&#8217;m convinced there are bugs in there.)</p>

<p>I still don&#8217;t know how to write idiomatic (typo: idiotmatic) Ruby, so this is going to be very rough. Still, it feels natural to me, minus one or two hitches:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">ARGS = <span style="color:#996600;">&quot;--bar=baz&quot;</span>
CMD = <span style="color:#996600;">&quot;~/bin/foo&quot;</span>
KEY = <span style="color:#006600; font-weight:bold;">/</span>quux<span style="color:#006600; font-weight:bold;">/</span>
MIN = <span style="color:#006666;">0</span>
MAX = <span style="color:#006666;">10000</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> main
  <span style="color:#006600; font-weight:bold;">&#40;</span>MIN..<span style="color:#9900CC;">MAX</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span>
    out = <span style="color:#006600; font-weight:bold;">%</span>x<span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#008000; font-style:italic;">#{CMD} #{i} #{ARGS} ]</span>
    out.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'<span style="color:#000099;">\n</span>'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>line<span style="color:#006600; font-weight:bold;">|</span>
      KEY.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span>line<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>m<span style="color:#006600; font-weight:bold;">|</span>
        value = line.<span style="color:#CC0066; font-weight:bold;">split</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">' '</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        <span style="color:#CC0066; font-weight:bold;">print</span> <span style="color:#996600;">&quot;#{i},#{value}<span style="color:#000099;">\n</span>&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<p>I&#8217;m not confident about the outer loop once again, and I&#8217;m not sure the call to match() will do what I want, let alone whether it&#8217;s elegant. Still, I feel pretty good about it. I love Ruby&#8217;s pattern of passing in blocks.</p>

<p>Fortunately or unfortunately, I had to use Python. And don&#8217;t get me wrong: I love Python. It is through Python that I learned to love scripting languages. Processing a file line by line was, I think, the real epiphany. And list comprehensions are wonderfully expressive.</p>

<p>But man alive is it <strong>awful</strong> for this sort of thing. I&#8217;m not even going to bother writing it out in Python. I&#8217;ll just excerpt, from the <a href="http://docs.python.org/library/subprocess.html#replacing-bin-sh-shell-backquote">2.7 subprocess docs</a>. Here&#8217;s what they say should replace backticks <code>output = \</code>mycmd myarg&#96;`:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">output = Popen<span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;mycmd&quot;</span>, <span style="color: #483d8b;">&quot;myarg&quot;</span><span style="color: black;">&#93;</span>, stdout=PIPE<span style="color: black;">&#41;</span>.<span style="color: black;">communicate</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span></pre></div></div>


<p>Mind you, this is if you did <code>from subprocess import *</code>. Generally I don&#8217;t, which means it ends up looking like this:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">output = \
  <span style="color: #dc143c;">subprocess</span>.<span style="color: black;">Popen</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;mycmd&quot;</span>, <span style="color: #483d8b;">&quot;myarg&quot;</span><span style="color: black;">&#93;</span>, <span style="color: #dc143c;">subprocess</span>.<span style="color: black;">stdout</span>=PIPE<span style="color: black;">&#41;</span>.\
  communicate<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span></pre></div></div>


<p>Yes, once you have it written, sequestered in its own function that you never touch again, it&#8217;s not so bad. However, this is firmly in the category of something I will not be able to (and have not been able to) remember months later.</p>

<p>It is also not discoverable in the sense that it&#8217;s highly particular&#8212; <code>stdout=PIPE</code>? Really? Compare and contrast opening a file (<code>for line in open('somefile'): print foo(line)</code> or <code>[foo(line) for line in open('somefile')</code>) with this monster. Even my Ruby example could have used backticks if I hadn&#8217;t remembered the <code>%x</code> syntax. The best I can say about <code>subprocess</code> is that it&#8217;s a) better than <code>Popen</code> in Python 2.4 (or whatever), and b) it&#8217;s easier to search the web for than <code>%x</code>.</p>

<p>The kicker of course is that rest of the Python script was very easy to write! However, since calling the binary was changing some external state, though, I had to make sure it was doing the right thing. In the end building and testing the call to <code>subprocess.Popen()</code> took longer than the rest of the script. In an otherwise elegant, no-bullshit, batteries included language, the <code>subprocess</code> module is a terrible blemish. It doesn&#8217;t look any better in Python 3.0, either, unfortunately.</p>

<p>Even more unfortunately, this is ultimately why it would be my preference to use either Ruby or shell. Ruby seems to work well for a variety of tasks, from writing a full-fledged webapp to some grungy text manipulation. You don&#8217;t have to compromise because it&#8217;s quite easy to use it for Python-y things as well as Perl-y things. It&#8217;s just a shame that Python seems to treat this case with a bizarre kind of fussiness incongruent with the rest of the language and standard library.</p>
]]></content:encoded>
			<wfw:commentRss>https://incrediblevehicle.com/2011/08/31/python-python-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Markin&#8217; it down</title>
		<link>https://incrediblevehicle.com/2009/07/19/markin-it-down/</link>
		<comments>https://incrediblevehicle.com/2009/07/19/markin-it-down/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 04:36:35 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://incrediblevehicle.com/?p=613</guid>
		<description><![CDATA[I&#8217;m giving Markdown a shot. I got sick of HTML. It&#8217;s cumbersome and not pleasant to read, and wyswig editors that operate with HTML under the hood have their own set of problems. Given the choice, I prefer a Wiki-like syntax. Markdown&#8217;s a lot like this; it&#8217;s human-readable but powerful in terms of the formatting [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m giving <a href="http://wordpress.org/extend/plugins/markdown-for-wordpress-and-bbpress/" title="John Gruber's Markdown">Markdown</a> a shot. I got sick of HTML. It&#8217;s cumbersome and not pleasant to read, and wyswig editors that operate with HTML under the hood have their own set of problems. Given the choice, I prefer a Wiki-like syntax. Markdown&#8217;s a lot like this; it&#8217;s human-readable but powerful in terms of the formatting it allows you.</p>

<p>Once I found a <a href="http://wordpress.org/extend/plugins/markdown-for-wordpress-and-bbpress/" title="John Gruber's Markdown">WordPress plugin</a> and a <a href="http://plasticboy.com/markdown-vim-mode/">Vim syntax file</a>, I was all set.</p>

<p>What&#8217;s more, Ubuntu has a package called <a href="http://www.freewisdom.org/projects/python-markdown/">python-markdown</a>. I&#8217;m not sure whether or not I&#8217;ll use Markdown for anything other than blog posting, but on the other hand, it&#8217;s awfully tempting to take advantage of this kind of intuitive, powerful formatting.</p>

<p>Yes, I&#8217;ve taken a step down a dark path: I&#8217;m writing blog posts in Vim, in Linux. Although I use it for coding as often as possible, I&#8217;ve thus far avoided it for anything like actual writing.</p>
]]></content:encoded>
			<wfw:commentRss>https://incrediblevehicle.com/2009/07/19/markin-it-down/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>readline, Python, IPython, and Mac OS X</title>
		<link>https://incrediblevehicle.com/2009/06/11/readline-python-ipython-and-mac-os-x/</link>
		<comments>https://incrediblevehicle.com/2009/06/11/readline-python-ipython-and-mac-os-x/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 03:18:43 +0000</pubDate>
		<dc:creator>Matthew</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[ipython]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[problems]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://incrediblevehicle.com/?p=132</guid>
		<description><![CDATA[All right, so maybe I&#8217;ll finally use this space. If you&#8217;ve tried to get IPython working on Mac OS X Leopard (that&#8217;d be 10.5, and 10.5.7 in particular) with an Intel based CPU, you&#8217;ve probably had some problems. I know I did! Let me cut to the chase, with a more technical explanation to follow. Oh, [...]]]></description>
			<content:encoded><![CDATA[<p>All right, so maybe I&#8217;ll finally use this space.</p>

<p>If you&#8217;ve tried to get IPython working on Mac OS X Leopard (that&#8217;d be 10.5, and 10.5.7 in particular) with an Intel based CPU, you&#8217;ve probably had some problems. I know I did! Let me cut to the chase, with a more technical explanation to follow. Oh, and some mild bitching, too.</p>

<p>I&#8217;m following the instructions I originally saw <a href="https://bugs.launchpad.net/ipython/+bug/254023">here</a>, on IPython&#8217;s Launchpad site.  Yes, my instructions are merely a reprint of someone else&#8217;s bug report. More on that after I explain.</p>

<h3>Quick instructions</h3>

<p>I&#8217;m going to assume you haven&#8217;t downloaded anything, although if, like me, you wrestled with this for a while, you can still do these steps and it&#8217;ll work. It worked for me, anyway. :/</p>

<ol>
    <li>Download the <code>.egg</code> for readline, presumably the latest version. Get IPython if you haven&#8217;t already. As of this writing, you can get it here at the <a href="http://ipython.scipy.org/moin/Download">IPython download site</a>. You can s/i386/fat/ if you like.</li>
    <li>Copy it to a directory, such as <code>~/python</code>.</li>
    <li>You can try to install readline and IPython: sudo easy_install readline ipython. One or both will fail.</li>
    <li>Open /usr/local/bin/ipython in your favorite text editor, and replace the contents of the file as described at the IPython Launchpad bug linked above. The key is to hardcode readline into the Python system path immediately after sys, and then to launch IPython explicitly.</li>
    <li>Launch ipython.</li>
</ol>

<p>You <em>should</em> be OK now, tabbing and all. If you haven&#8217;t checked this shit out, <a href="http://ipython.scipy.org/doc/stable/html/interactive/shell.html">using IPython for your system shell</a>, I highly recommend that you do. It&#8217;s none too shabby. <a href="http://ipython.scipy.org/doc/stable/html/interactive/shell.html">There&#8217;s a book on this, too.</a></p>

<p>Technical stuff after the jump.</p>

<p><span id="more-132"></span></p>

<h3>wtf, man</h3>

<p>So, here&#8217;s the skinny. It took me an hour or two to figure this out, which is way too long. I&#8217;m writing this post so that hopefully I can nail some of the search terms that weren&#8217;t around when I looked for it on the Googles. I&#8217;m mentioning a whole bunch of keywords and specific stuff in the hopes that the next person who has this problem gets here or to the Launchpad site and manages to solve their problem.</p>

<p>Anyway, the technical background: IPython wants GNU&#8217;s readline library (tabbing!), but Mac OS X ships with libedit. If you somehow manage to get IPython to work, tabbing won&#8217;t because IPython is using libedit. It sucks and practically defeats the purpose of IPython. I had this working briefly, and then I broke it somehow. Whee!</p>

<p>You can download the readline egg and try to install it with easy_install. It will try to compile, then error out. In particular, it errors out on <code>Modules/readline.c:681</code> a bunch of times. I&#8217;m not 100% sure why it does this, and I&#8217;m too lazy to remember/figure it out again. I think it&#8217;s trying to compile the readline lib specifically for Python and failing because of some mismatch. It sucks and it makes me sad inside.</p>

<p>When I tried to run IPython anyway, I got a bunch of errors about unable to find an entry point. I suspect this is some failure related to  easy_install, egg, or pkg_resources and readline being missing, although it&#8217;s vastly unintuitive if so. You&#8217;ll get an ImportError related to console_scripts and ipython. It&#8217;ll say entry point not found.</p>

<p>The fix appears to be skipping the egg, easy_install, pkg_resource shenanigans by explicitly adding readline to your path and then explicitly invoking IPython instead of giving something else a chance to error out. Sounds good to me!</p>

<h3>readline + IPython + Fink?</h3>

<p>I didn&#8217;t try doing anything with <a href="http://www.finkproject.org/">Fink</a>. Fink does have both a version of IPython and readline, so it&#8217;s possible that Fink would be a better choice overall. Honestly, I&#8217;d try that before anything else. I was too stubborn to give up halfway through.</p>

<p>Of course, not having tried it, I don&#8217;t know that it&#8217;ll work. It&#8217;s gotta be less painful than the hackery above, though, right? Right? I mean, what could possibly go wrong?</p>
]]></content:encoded>
			<wfw:commentRss>https://incrediblevehicle.com/2009/06/11/readline-python-ipython-and-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
