<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">
<channel>
    <title>TechOpinionation - Python</title>
    <link>http://joshuakugler.com/</link>
    <description>The life of a programmer/system admin</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.5.1 - http://www.s9y.org/</generator>
    <pubDate>Thu, 31 Dec 2009 15:04:24 GMT</pubDate>

    <image>
        <url>http://joshuakugler.com/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: TechOpinionation - Python - The life of a programmer/system admin</title>
        <link>http://joshuakugler.com/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>BetweenDict, a Python dict for value ranges</title>
    <link>http://joshuakugler.com/archives/30-BetweenDict,-a-Python-dict-for-value-ranges.html</link>
            <category>Python</category>
    
    <comments>http://joshuakugler.com/archives/30-BetweenDict,-a-Python-dict-for-value-ranges.html#comments</comments>
    <wfw:comment>http://joshuakugler.com/wfwcomment.php?cid=30</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://joshuakugler.com/rss.php?version=2.0&amp;type=comments&amp;cid=30</wfw:commentRss>
    

    <author>nospam@example.com (Joshua Kugler)</author>
    <content:encoded>
    I was doing some programming today (no, really?) and had need of a data structure that would return a value based on the key falling within a given range.  Kind of like a dict, but each key in the dict would be two values, between which the querying key would fall. Thus was born BetweenDict.  It&#039;s short and sweet, and to the point. And works for what I need.&lt;br /&gt;
&lt;div class=&quot;python&quot; style=&quot;text-align: left&quot;&gt;&lt;br /&gt;&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;class&lt;/span&gt; BetweenDict&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;dict&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;br /&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0000cd;&quot;&gt;__init__&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;self&lt;/span&gt;, d = &lt;span style=&quot;color: black;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;for&lt;/span&gt; k,v &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;in&lt;/span&gt; d.&lt;span style=&quot;color: black;&quot;&gt;items&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #008000;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;k&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt; = v&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0000cd;&quot;&gt;__getitem__&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;self&lt;/span&gt;, key&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;for&lt;/span&gt; k, v &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;in&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;self&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;items&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;if&lt;/span&gt; k&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff4500;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt; &amp;lt;= key &amp;lt; k&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;:&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; v&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;raise&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;KeyError&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;&quot;Key &#039;%s&#039; is not between any values in the BetweenDict&quot;&lt;/span&gt; % key&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0000cd;&quot;&gt;__setitem__&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;self&lt;/span&gt;, key, value&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;try&lt;/span&gt;:&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;len&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;key&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt; == &lt;span style=&quot;color: #ff4500;&quot;&gt;2&lt;/span&gt;:&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;if&lt;/span&gt; key&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff4500;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt; &amp;lt; key&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;:&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #008000;&quot;&gt;dict&lt;/span&gt;.&lt;span style=&quot;color: #0000cd;&quot;&gt;__setitem__&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;self&lt;/span&gt;, &lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;key&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff4500;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;, key&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;, value&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;else&lt;/span&gt;:&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;raise&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;RuntimeError&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;&#039;First element of a BetweenDict key &#039;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #483d8b;&quot;&gt;&#039;must be strictly less than the &#039;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #483d8b;&quot;&gt;&#039;second element&#039;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;else&lt;/span&gt;:&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;raise&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;ValueError&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;&#039;Key of a BetweenDict must be an iterable &#039;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #483d8b;&quot;&gt;&#039;with length two&#039;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;except&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;TypeError&lt;/span&gt;:&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;raise&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;TypeError&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;&#039;Key of a BetweenDict must be an iterable &#039;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #483d8b;&quot;&gt;&#039;with length two&#039;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;def&lt;/span&gt; &lt;span style=&quot;color: #0000cd;&quot;&gt;__contains__&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;self&lt;/span&gt;, key&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;:&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;try&lt;/span&gt;:&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #008000;&quot;&gt;self&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;key&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;or&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;True&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;except&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;KeyError&lt;/span&gt;:&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #008000;&quot;&gt;False&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;/div&gt; 
    </content:encoded>

    <pubDate>Thu, 31 Dec 2009 14:50:04 +0000</pubDate>
    <guid isPermaLink="false">http://joshuakugler.com/archives/30-guid.html</guid>
    <creativeCommons:license>http://creativecommons.org/licenses/by-sa/3.0/</creativeCommons:license><category>between</category>
<category>dict</category>
<category>python</category>

</item>
<item>
    <title>Basie sounds good...but only SVN?</title>
    <link>http://joshuakugler.com/archives/28-Basie-sounds-good...but-only-SVN.html</link>
            <category>Django</category>
            <category>Python</category>
    
    <comments>http://joshuakugler.com/archives/28-Basie-sounds-good...but-only-SVN.html#comments</comments>
    <wfw:comment>http://joshuakugler.com/wfwcomment.php?cid=28</wfw:comment>

    <slash:comments>2</slash:comments>
    <wfw:commentRss>http://joshuakugler.com/rss.php?version=2.0&amp;type=comments&amp;cid=28</wfw:commentRss>
    

    <author>nospam@example.com (Joshua Kugler)</author>
    <content:encoded>
    &lt;em&gt;Started a comment on &lt;a href=&quot;http://pyre.third-bit.com/blog/archives/3350.html&quot;&gt;this post&lt;/a&gt; but it got a little long.&lt;/em&gt;&lt;br /&gt;
&lt;br /&gt;
So, I follow &lt;a href=&quot;http://planet.python.org/&quot;&gt;Planet Python&lt;/a&gt; and have seen &lt;a href=&quot;http://pyre.third-bit.com/blog&quot;&gt;Greg Wilson&#039;s&lt;/a&gt; posts on the &lt;a href=&quot;http://basieproject.org/&quot;&gt;Basie&lt;/a&gt; project.&lt;br /&gt;
&lt;blockquote&gt;Basie is a web-based software project forge that integrates revision control, issue tracking, mailing lists, wikis, status dashboards, and other tools that developers need to work effectively in teams.&lt;/blockquote&gt;&lt;br /&gt;
Basie uses &lt;a href=&quot;http://www.djangoproject.com/&quot;&gt;Django&lt;/a&gt; and &lt;a href=&quot;http://jquery.com/&quot;&gt;jQuery&lt;/a&gt; among other technologies to make a leaner, meaner, multi-project &quot;forge.&quot;&lt;br /&gt;
&lt;br /&gt;
I&#039;ve read up a bit on Basie.  Modern framework! jQuery! Multiple projects! Python! Only Subversion!  What?  Nearly every other* project tracking system out there (even Trac&#039;s shoe-horned support) has support for alternate VCS&#039;s: Git, Darcs, Bzr, Mercurial, etc.  Are you serious?  With countless hours invested, and probably 30+ people having worked on the code base, couldn&#039;t &quot;multi VCS&quot; have been a requirement from the get-go?  Granted, I&#039;ve never tried it, but as Trac hacks, and Redmine, have proven, it can be done.&lt;br /&gt;
&lt;br /&gt;
I think it&#039;s great that we have a project tracking system that is based on modern web framework technologies, but I really think Basie is going to be at a disadvantage out of the gate because it does not support (granted, minority, but growing) VCS&#039;s. I hope they are able to rectify this soon: I&#039;d love to see Basie grow into a viable competitor to Redmine.  Side note: I love Redmine, but a system in Python allows us to use our intellectual investment to contribute to our VCS; there is very little Ruby knowledge in our shop, so it&#039;s harder to give back.&lt;br /&gt;
&lt;br /&gt;
Something else that caught my eye on the Basie site:&lt;br /&gt;
&lt;blockquote&gt;Why Build Another Forge?&lt;br /&gt;
Because none of the others meet our needs.... Redmine provides many of the features we want, but is still immature;&lt;/blockquote&gt;&lt;br /&gt;
Can it be clarified when this was written?  We currently run Redmine 0.8.6 (with 0.9 around the corner).  It has been VERY stable, very able, and everything we need in a PTS.  Other than using Python, is there any reason you did not simply choose to invest the time of 30+ people in an existing PTS instead of starting your own from scratch?&lt;br /&gt;
&lt;br /&gt;
Again, this isn&#039;t a rant, or to put down the project: I think it&#039;s great, and I hope it gets traction in the PTS world. It&#039;s just a design decision and your rationale of an &quot;immature Redmine&quot; that got me curious.&lt;br /&gt;
&lt;br /&gt;
*&quot;Every other&quot; meaning &quot;Every other that I am aware of.&quot;  I&#039;m sure there are plenty of PTS&#039;s that I&#039;m not aware of. 
    </content:encoded>

    <pubDate>Wed, 23 Dec 2009 16:26:08 +0000</pubDate>
    <guid isPermaLink="false">http://joshuakugler.com/archives/28-guid.html</guid>
    <creativeCommons:license>http://creativecommons.org/licenses/by-sa/3.0/</creativeCommons:license><category>basie</category>
<category>django</category>
<category>git</category>
<category>jquery</category>
<category>python</category>
<category>redmine</category>
<category>svn</category>
<category>vcs</category>

</item>
<item>
    <title>Don't use strptime, use a regex</title>
    <link>http://joshuakugler.com/archives/27-Dont-use-strptime,-use-a-regex.html</link>
            <category>Python</category>
    
    <comments>http://joshuakugler.com/archives/27-Dont-use-strptime,-use-a-regex.html#comments</comments>
    <wfw:comment>http://joshuakugler.com/wfwcomment.php?cid=27</wfw:comment>

    <slash:comments>2</slash:comments>
    <wfw:commentRss>http://joshuakugler.com/rss.php?version=2.0&amp;type=comments&amp;cid=27</wfw:commentRss>
    

    <author>nospam@example.com (Joshua Kugler)</author>
    <content:encoded>
    I am using Python to do some data file processing, converting data from a horrendously verbose, repetitive format to a nice, clean, CSV format.  The date and time are in two different fields, and the date is in MM/DD/YYYY format, plus, the MM and DD might be one or two characters. That is, January is 1, not 01.&lt;br /&gt;
&lt;br /&gt;
I am converting the timestamp to ISO format, so I was using time.strptime to extract the date/time and time.strftime to generate to proper ISO formatted date, like so:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;python&quot; style=&quot;text-align: left&quot;&gt;&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #dc143c;&quot;&gt;time&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;strftime&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;&quot;%Y-%m-%d %H:%M:%S&quot;&lt;/span&gt;, &lt;span style=&quot;color: #dc143c;&quot;&gt;time&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;strptime&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;ts, &lt;span style=&quot;color: #483d8b;&quot;&gt;&quot;%m/%d/%Y %H:%M:%S&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
On the smallest of my data files, the processing was taking 13 to 15 seconds.  I profiled it, and found that in a 13 second run, strptime was taking 8.755 seconds of that, and it was calling _getlang(), _parse_localename(), and the like very time.&lt;br /&gt;
&lt;br /&gt;
So, thought I, regexes are pretty efficient, I wonder if that would reduce the run time any.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;python&quot; style=&quot;text-align: left&quot;&gt;ts_re = &lt;span style=&quot;color: #dc143c;&quot;&gt;re&lt;/span&gt;.&lt;span style=&quot;color: #008000;&quot;&gt;compile&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;&#039;^(&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\d&lt;/span&gt;{1,2})/(&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\d&lt;/span&gt;{1,2})/(&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\d&lt;/span&gt;{4}) (&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\d&lt;/span&gt;{2}:&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\d&lt;/span&gt;{2}:&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\d&lt;/span&gt;{2})&#039;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;m = ts_re.&lt;span style=&quot;color: black;&quot;&gt;match&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;ts&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: black;&quot;&gt;groups&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #ff7700;font-weight:bold;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #483d8b;&quot;&gt;&quot;%s-%02d-%02d %s&quot;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt; % &lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;m&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff4500;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;, &lt;span style=&quot;color: #008000;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;m&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff4500;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;, &lt;span style=&quot;color: #008000;&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#40;&lt;/span&gt;m&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff4500;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;, m&lt;span style=&quot;color: black;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff4500;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: black;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
(The re.compile() call is at the module level, outside the function, so it is only run once.)&lt;br /&gt;
&lt;br /&gt;
My overall run time dropped to about 5 seconds, a little over 1/3 of the time it took previously.  My convert_timestamp() function, which previously had consumed nearly 10 seconds, was only taking about 1.3 seconds now.&lt;br /&gt;
&lt;br /&gt;
Sometimes regexes &lt;strong&gt;are&lt;/strong&gt; the answer.&lt;br /&gt;
&lt;br /&gt;
 
    </content:encoded>

    <pubDate>Wed, 23 Sep 2009 11:28:48 +0000</pubDate>
    <guid isPermaLink="false">http://joshuakugler.com/archives/27-guid.html</guid>
    <creativeCommons:license>http://creativecommons.org/licenses/by-sa/3.0/</creativeCommons:license><category>profiling</category>
<category>python</category>
<category>regex</category>
<category>strftime</category>
<category>strptime</category>

</item>
<item>
    <title>Building Python Eggs with C Extensions on Windows</title>
    <link>http://joshuakugler.com/archives/13-Building-Python-Eggs-with-C-Extensions-on-Windows.html</link>
            <category>Python</category>
    
    <comments>http://joshuakugler.com/archives/13-Building-Python-Eggs-with-C-Extensions-on-Windows.html#comments</comments>
    <wfw:comment>http://joshuakugler.com/wfwcomment.php?cid=13</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://joshuakugler.com/rss.php?version=2.0&amp;type=comments&amp;cid=13</wfw:commentRss>
    

    <author>nospam@example.com (Joshua Kugler)</author>
    <content:encoded>
    I recently had the task of building Python Eggs on Windows that had C extensions.  I did the usual googling, and found a few HOWTOs, but nothing I could find was very concise and straightforward.  So, I present to you a very concise, very straightforward guide.&lt;br /&gt;
&lt;br /&gt;
&lt;h1&gt;Setting up the Build Environment&lt;/h1&gt;&lt;br /&gt;
&lt;br /&gt;
We are assuming all installers are allowed to install to their default locations.&lt;br /&gt;
&lt;br /&gt;
Download and install Python 2.5 and/or Python 2.4 from python.org. You may have to use Python 2.4.4 since that was the latest 2.4 series to have an installer at time of writing.  Whichever you want associated with .py files, install last.&lt;br /&gt;
&lt;br /&gt;
Download and install SetupTools for Python (both 2.4 and 2.5) &lt;a href=&quot;http://pypi.python.org/pypi/setuptools/&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
MingW files are &lt;a href=&quot;http://sourceforge.net/project/showfiles.php?group_id=2435&quot;&gt;here&lt;/a&gt;. Download and run the latest version of &quot;Automated MinGW Installer.&quot; You only need to install g++, and maybe not even that. When it prompts you for old/current/preview version of the MinGW system, select current.&lt;br /&gt;
&lt;br /&gt;
Download and run the current version of &quot;MSYS Base System.&quot;&lt;br /&gt;
&lt;br /&gt;
Open up the MinGW shell, and execute these commands:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;bash&quot; style=&quot;text-align: left&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;cd&lt;/span&gt; /&lt;br /&gt;mkdir mingw&lt;br /&gt;mkdir code &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;#Convenience, if you want to mount your code&#039;s dir at an &amp;quot;easy&amp;quot; spot&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: #ff0000;&quot;&gt;&quot;c:/MinGW /mingw&lt;br /&gt;c:/path/to/code /code&quot;&lt;/span&gt; &amp;gt; /etc/fstab&lt;br /&gt;&amp;#160;&lt;/div&gt;&lt;br /&gt;
Create the file &lt;code&gt;c:\PythonNN\Lib\distutils\distutils.cfg&lt;/code&gt; and put the following in it, where NN is replaced with 24 or 25, depending on version::&lt;br /&gt;
&lt;blockquote&gt;[build]&lt;br /&gt;
compiler = mingw32&lt;/blockquote&gt;&lt;br /&gt;
Do this for each version installed.&lt;br /&gt;
&lt;br /&gt;
&lt;h1&gt;Building the Eggs&lt;/h1&gt;&lt;br /&gt;
MinGW mounts your drives on the root directory, so your C: drive will be at /c, D: drive at /d, and so on.  Open up a MinGW shell, and:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;bash&quot; style=&quot;text-align: left&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;cd&lt;/span&gt; /code &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# or /c/path/to/code, if you didn&#039;t mount /code&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Depending on which package you&#039;re building, you&#039;ll either use setup.py&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# or extended_setup.py.&amp;#160; I&#039;m using setup.py here as a placeholder. Replace as appropriate.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Python 2.4:&lt;/span&gt;&lt;br /&gt;/c/python24/python setup.py build_static &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# if needed&lt;/span&gt;&lt;br /&gt;/c/python24/python setup.py bdist_egg&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# Python 2.5:&lt;/span&gt;&lt;br /&gt;/c/python25/python setup.py build_static &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;# if needed&lt;/span&gt;&lt;br /&gt;/c/python25/python setup.py bdist_egg&lt;br /&gt;&amp;#160;&lt;/div&gt;&lt;br /&gt;
You&#039;ll now have eggs for your architecture and OS.  Enjoy!&lt;br /&gt;
 
    </content:encoded>

    <pubDate>Fri, 14 Nov 2008 15:13:31 +0000</pubDate>
    <guid isPermaLink="false">http://joshuakugler.com/archives/13-guid.html</guid>
    <creativeCommons:license>http://creativecommons.org/licenses/by-sa/3.0/</creativeCommons:license><category>bash</category>
<category>c</category>
<category>eggs</category>
<category>extensions</category>
<category>mingw</category>
<category>msys</category>
<category>python</category>

</item>

</channel>
</rss>
