<?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>sean{e}lavelle.com</title>
	<atom:link href="http://www.seanelavelle.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.seanelavelle.com</link>
	<description>Coding, Photography, Travel and whatever else is exciting to me these days</description>
	<lastBuildDate>Sun, 08 Jan 2012 14:14:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Python IDE Setup</title>
		<link>http://www.seanelavelle.com/2012/01/08/python-ide-setup/</link>
		<comments>http://www.seanelavelle.com/2012/01/08/python-ide-setup/#comments</comments>
		<pubDate>Sun, 08 Jan 2012 14:14:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.seanelavelle.com/?p=71</guid>
		<description><![CDATA[I occasionally get some questions about how I do my python development and though I would share it. &#160; For my main IDE on my windows box I use Eclipse with the PyDev module installed: http://marketplace.eclipse.org/content/pydev-python-ide-eclipse &#160; Since most of &#8230; <a href="http://www.seanelavelle.com/2012/01/08/python-ide-setup/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I occasionally get some questions about how I do my python development and though I would share it.</p>
<p>&nbsp;</p>
<p>For my main IDE on my windows box I use Eclipse with the PyDev module installed:</p>
<p><a href="http://marketplace.eclipse.org/content/pydev-python-ide-eclipse" target="_blank">http://marketplace.eclipse.org/content/pydev-python-ide-eclipse</a></p>
<p><a href="http://www.seanelavelle.com/wp-content/uploads/2012/01/image002.jpg"><img class="alignnone size-medium wp-image-72" title="image002" src="http://www.seanelavelle.com/wp-content/uploads/2012/01/image002-300x225.jpg" alt="" width="300" height="225" /></a></p>
<p>&nbsp;</p>
<p>Since most of my development is on Linux, I have the Remote System Explorer plugin installed which lets me create and edit files on our linux server over sftp like they were local to my workstation:</p>
<p><a href="http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.rse.doc.user/gettingstarted/g1installing.html" target="_blank">http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.rse.doc.user/gettingstarted/g1installing.html</a></p>
<p><a href="http://www.seanelavelle.com/wp-content/uploads/2012/01/image004.png"><img class="alignnone size-medium wp-image-73" title="image004" src="http://www.seanelavelle.com/wp-content/uploads/2012/01/image004-154x300.png" alt="" width="154" height="300" /></a></p>
<p>&nbsp;</p>
<p>Last but not least, I installed Eclipse Color Theme which is an easy way to install themes for eclipse:</p>
<p><a href="http://marketplace.eclipse.org/content/eclipse-color-theme" target="_blank">http://marketplace.eclipse.org/content/eclipse-color-theme</a></p>
<p>I even when an made a theme (kind of Borland blue, not shown above) you can download here:</p>
<p><a href="http://www.eclipsecolorthemes.org/?view=theme&amp;id=4514" target="_blank">http://www.eclipsecolorthemes.org/?view=theme&amp;id=4514</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.seanelavelle.com/2012/01/08/python-ide-setup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Speeding Python Up With Pypy</title>
		<link>http://www.seanelavelle.com/2012/01/06/66/</link>
		<comments>http://www.seanelavelle.com/2012/01/06/66/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 14:02:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.seanelavelle.com/?p=66</guid>
		<description><![CDATA[I&#8217;ve been working on some code that will use some supplied regular expressions to search through log files (I know, regex isn&#8217;t that efficient, yadda, yadda, yadda, but these were the requirements). The issue I was running into was that &#8230; <a href="http://www.seanelavelle.com/2012/01/06/66/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on some code that will use some supplied regular expressions to search through log files (I know, regex isn&#8217;t that efficient, yadda, yadda, yadda, but these were the requirements). The issue I was running into was that there was a lot of data. For example, I had 10 regexes that would search 36 gzipped files averaging 1.2 million lines each. The real issue was that these logs came in hourly, so if it couldn&#8217;t finish searching them all within an hour it was going to get backed up.</p>
<p>Being a good Pythonista, I followed the cardinal rules of:<br />
Get it right.<br />
Test it&#8217;s right.<br />
Profile if slow.<br />
Optimize.<br />
Repeat from 2.<br />
<a href="http://wiki.python.org/moin/PythonSpeed/PerformanceTips">http://wiki.python.org/moin/PythonSpeed/PerformanceTips</a></p>
<p>The problem was, after a while I sort of hit a wall. Nothing I did could make this code appreciably faster (of course this was with my limited knowlegde. I&#8217;m sure that more experienced Python programmers could optimize this code a lot better then I can, rewrite the regex bottleneck in C, etc) but I was at the end of my rope.</p>
<p>On thing led to another and I remembered reading about Pypy. Pypy is implementation of Python using a JIT (Just In Time Compiler) and other things that have lost there meaning for me since I did systems programming in college. &#8220;What the heck&#8221;, I thought, &#8220;I&#8217;ll give it a try&#8221;. Pypy is supposed to be highly compatible with CPython (the regular python implementation) and my code didn&#8217;t use any exotic libraries.</p>
<p>So I dumped the tarball on my linux machine, unzipped and ran my unmodified code against it, and DAMN was it fast.</p>
<p>CPython run:</p>
<pre>sean@linux1:~/code/python/hourly_alerts$ python alerter.py
Loaded regexes
Processing known_bad.log.gz
Searched 817051 lines in 119.398156166 seconds using filter</pre>
<p>Pypy Run</p>
<pre>sean@linux1:~/code/python/hourly_alerts$ /home/sean/bin/pypy-1.7/bin/pypy alerter.py
Loaded regexes
Processing known_bad.log.gz
Searched 817051 lines in 51.1275110245 seconds using filter</pre>
<p>More then twice as fast! Now I know that it was a totally unscientific test and all, but its great to see such an improvement right away.</p>
<p>I my also try Cython, but that looks like it doesn&#8217;t have quite the drop-in functionality of Pypy.</p>
<p>Here are the link to Pypy : <a href="http://pypy.org">http://pypy.org/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.seanelavelle.com/2012/01/06/66/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python : using filter and regular expressions to search a file</title>
		<link>http://www.seanelavelle.com/2012/01/03/python-using-filter-and-regular-expressions-to-search-a-file/</link>
		<comments>http://www.seanelavelle.com/2012/01/03/python-using-filter-and-regular-expressions-to-search-a-file/#comments</comments>
		<pubDate>Tue, 03 Jan 2012 13:57:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.seanelavelle.com/?p=60</guid>
		<description><![CDATA[I&#8217;ve been working on a script that searches files based on regular expressions and came up with a pretty neat way to do this  &#8211; using filter! (this may be old hat to more experienced Python programers, but I am &#8230; <a href="http://www.seanelavelle.com/2012/01/03/python-using-filter-and-regular-expressions-to-search-a-file/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a script that searches files based on regular expressions and came up with a pretty neat way to do this  &#8211; using filter! (this may be old hat to more experienced Python programers, but I am just starting to get comfortable with map/filter/etc&#8230;). In this example we compile our regex and filter the gzip file that we have read into memory and display the lines that match and the type of regex that they match on.</p>
<pre class="prettyprint">import re
import gzip

searchName = "Example Regex"
compiledRegex = re.compile(r'example' re.I)

dataFile = gzip.open(fileName, "rb")
#read in the file to memory
fullData = dataFile.readlines()
regexName = searchName
regexSearch = compiledRegex .search
#Filter for just the lines matching the regex
hitList = filter(regexSearch, fullData)
#hitList now is just a list of our matches
for item in hitList:
    print "MATCH:%s" % regexName
    print "ENTRY:%s" % item</pre>
<p>Obviously this code needs more to be at all usable, but this is the general idea and a pretty cool use of the filter function.</p>
<p>If you know of a better way, let me know in the comments.</p>
<p>References:<br />
Python Regular Expressions (re) : <a href="http://docs.python.org/library/re.html">http://docs.python.org/library/re.html</a><br />
Filter Function : <a href="http://docs.python.org/library/functions.html#filter">http://docs.python.org/library/functions.html#filter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.seanelavelle.com/2012/01/03/python-using-filter-and-regular-expressions-to-search-a-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>You don&#8217;t need regular expressions for most common matching operations in Python</title>
		<link>http://www.seanelavelle.com/2011/09/16/you-dont-need-regular-expressions-for-most-common-matching-operations-in-python/</link>
		<comments>http://www.seanelavelle.com/2011/09/16/you-dont-need-regular-expressions-for-most-common-matching-operations-in-python/#comments</comments>
		<pubDate>Fri, 16 Sep 2011 02:09:56 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.seanelavelle.com/?p=54</guid>
		<description><![CDATA[This is something that I find myself explaining a lot to team members that are just picking up Python.   Many times you see that you need to match part of a string just hop right into regular expressions.  I &#8230; <a href="http://www.seanelavelle.com/2011/09/16/you-dont-need-regular-expressions-for-most-common-matching-operations-in-python/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is something that I find myself explaining a lot to team members that are just picking up Python.   Many times you see that you need to match part of a string just hop right into regular expressions.  I know that I did it when I first started coding in Python.  The thing is though; the standard methods on strings handle most of the simple text matching that you do on a day to day basis.</p>
<p><span id="more-54"></span></p>
<p>[ED: Before we get into it though, regular expressions do have their place and are very powerful. None of this should be taken to mean "Don't use regular expressions EVER!" Use them where they make sense, but as always, try to write idiomatic python (<a href="http://jaynes.colorado.edu/PythonIdioms.html" target="_blank">http://jaynes.colorado.edu/PythonIdioms.html</a>) when possible.]</p>
<p>Let’s look at a couple examples:</p>
<p>Here we have 2 strings:</p>
<pre>myString = "This is a test string.  We'd like to match it."</pre>
<pre>myString2 = "We don't want to match this string."</pre>
<pre>stringList = [myString, myString2] #Just so we can iterate over them</pre>
<p>If we wanted to find the string that started with &#8220;This&#8221; we could do this:</p>
<pre>import re</pre>
<pre>for line in stringList:</pre>
<pre>      if (re.search("^This", line)):</pre>
<pre>            print "SUCCESS with line :" + line</pre>
<pre>      else:</pre>
<pre>            print "FAILURE with line :" + line</pre>
<p>This gives:</p>
<pre>SUCCESS with line :This is a test string.  We'd like to match it.</pre>
<pre>FAILURE with line :We don't want to match this string.</pre>
<p>We could do the same thing using the standard methods on a string in a (at least to me) cleaner and more pythonic way:</p>
<pre>for line in stringList:</pre>
<pre>      if line.startswith("This"):</pre>
<pre>            print "SUCCESS with line :" + line</pre>
<pre>      else:</pre>
<pre>            print "FAILURE with line :" + line</pre>
<pre>SUCCESS with line :This is a test string.  We'd like to match it.</pre>
<pre>FAILURE with line :We don't want to match this string.</pre>
<p>Using regex to see if a certain substring is in the line:</p>
<pre>import re</pre>
<pre>for line in stringList:</pre>
<pre>      if (re.search("test", line)):</pre>
<pre>            print "SUCCESS with line :" + line</pre>
<pre>      else:</pre>
<pre>            print "FAILURE with line :" + line</pre>
<p>This gives:</p>
<pre>SUCCESS with line :This is a test string.  We'd like to match it.</pre>
<pre>FAILURE with line :We don't want to match this string.</pre>
<p>Now using the built in operations:</p>
<pre>for line in stringList:</pre>
<pre>      if "This" in line:</pre>
<pre>            print "SUCCESS with line :" + line</pre>
<pre>      else:</pre>
<pre>            print "FAILURE with line :" + line</pre>
<pre>SUCCESS with line :This is a test string.  We'd like to match it.</pre>
<pre>FAILURE with line :We don't want to match this string.</pre>
<p>Keeping it simple always seems to me to be the best policy.  Of course this doesn&#8217;t meant that you should write hugely complex code to avoid using regexes.  It just means that sometimes they might not be the right choice.  Use the right tool for the job.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seanelavelle.com/2011/09/16/you-dont-need-regular-expressions-for-most-common-matching-operations-in-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Links</title>
		<link>http://www.seanelavelle.com/2011/08/28/links/</link>
		<comments>http://www.seanelavelle.com/2011/08/28/links/#comments</comments>
		<pubDate>Sun, 28 Aug 2011 10:00:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.seanelavelle.com/?p=31</guid>
		<description><![CDATA[The yield keyword in Python - A great discussion on iterators and generators Understanding Python Decorators - I&#8217;d never head of decorators until I saw this link and now can think of a bunch of uses for them In Defense of the &#8230; <a href="http://www.seanelavelle.com/2011/08/28/links/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://stackoverflow.com/questions/231767/the-python-yield-keyword-explained" target="_blank">The yield keyword in Python</a> - A great discussion on iterators and generators</p>
<p><a href="http://stackoverflow.com/questions/739654/understanding-python-decorators/1594484#1594484" target="_blank">Understanding Python Decorators</a> - I&#8217;d never head of decorators until I saw this link and now can think of a bunch of uses for them</p>
<p><a href="http://www.slate.com/id/2301435" target="_blank">In Defense of the Internet Craftsman</a> - &#8220;In Gutenberg&#8217;s era, the printmaker, not the machine, determined the subject matter of his work. No printing press could impose terms of service that dictated the language or content that could be printed. Instead, the craftsman was in full control of his speech. Yet these restrictions are being hardwired into modern technologies.&#8221;<br />
<a href="http://eriwen.com/tools/wikify-yourself/" target="_blank"><br />
Why Every Programmer Should Have A Tiddlywiki</a> - I&#8217;ve used tiddlywiki&#8217;s before, but Eric shows a great way to start using a tiddlywiki to keep track of your projects and todo&#8217;s.</p>
<p><a href="http://krondo.com/wp-content/uploads/2009/08/twisted-intro.html" target="_blank">An Introduction to Asynchronous Programming and Twisted</a> - This is not short, in fact it is probably book length and I have not read more then the beginning, but Twisted is something that I&#8217;ve always been really keen to learn and this looks like it might be a good introduction to it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seanelavelle.com/2011/08/28/links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Command Line Processing in Python &#8211; Several Options</title>
		<link>http://www.seanelavelle.com/2011/08/24/command-line-processing-in-python-several-options/</link>
		<comments>http://www.seanelavelle.com/2011/08/24/command-line-processing-in-python-several-options/#comments</comments>
		<pubDate>Wed, 24 Aug 2011 02:06:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.seanelavelle.com/?p=35</guid>
		<description><![CDATA[Processing command line parameters is one of the most common tasks that any programmer will do.  Luckily for us, Python has several options for quickly and easily taking arguments from the command line.  This is by no means an exhaustive &#8230; <a href="http://www.seanelavelle.com/2011/08/24/command-line-processing-in-python-several-options/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Processing command line parameters is one of the most common tasks that any programmer will do.  Luckily for us, Python has several options for quickly and easily taking arguments from the command line.  This is by no means an exhaustive or authoritative look at how to do this, just a comparison of several ways that I&#8217;ve run across in the past.</p>
<p><span id="more-35"></span><br />
<strong>sys.argv Method</strong><br />
Using sys.argv is probably the first way everyone processes options and it is a great quick and dirty way to do it with not a lot of coding.</p>
<p>Take a simple example:<br />
<code><br />
$ myprog.py somehost<br />
Connecting to somehost...<br />
</code><br />
In this trivial example, we pass a host to the program which (nominally) connects to the host (all it actually does is print connecting, but that is besides the point)</p>
<p>The code would be :</p>
<pre>
#!/usr/local/bin/python

import sys

host = sys.argv[1]
print "Connecting to" + host + "..."
</pre>
<p>What is happening here is that python takes all the parameters that we give them on a command line and shoves them into sys.argv. One thing to note, sys.argv[0] is always the name of the script.  So if we know the positions of the arguments or are only expecting a very limited argument set, sys.argv is a quick and easy way to access the command line parameters.  The problem with sys.argv is that it doesn&#8217;t handle more complex command line options well (or at least easily).<br />
<a href="http://springpadit.com/springpad/%20http://docs.python.org/library/sys.html#sys.argv"></p>
<p>http://docs.python.org/library/sys.html#sys.argv</a></p>
<p><strong>Using getopt</strong><br />
getopt should look pretty familiar to anyone that has worked with C before and allows us to do all the command line parsing that we expect in most CLI programs (ie pass values, handle long and short names, etc).</p>
<p>for example<br />
<code><br />
$ myprog2.py --message "Message to print" -n 5<br />
Message to print<br />
Message to print<br />
Message to print<br />
Message to print<br />
Message to print<br />
</code><br />
This program takes 2 parameters, a message to print and  the number or times to print.  We can easily set to to recognize the options for the message to be either -m or &#8211;message and the number of times to print it as -n or &#8211;number with getopt as demonstrated below:</p>
<pre>
#!/usr/local/bin/python

import sys
import getopt

try:
    optsList, argsList = getopt.getopt(sys.argv[1:], "m:n:", ["message=", "number="])
except getopt.GetoptError, err:
    #Error handling for unknown or incorrect number of options
    print str(err)
    sys.exit(2)
for opt, arg in optsList:
    if opt in ('-m', '--message'):
        messageText = arg
    elif opt in ('-n', '--number'):
        numberToPrint = int(arg)
    else:
        print "Unhandled option"
        sys.exit(2)

i=0
while i in range(numberToPrint):
    print messageText
    i=i+1
</pre>
<p>For a more indepth looks, here is the documentation: <a href="http://docs.python.org/library/getopt.html">http://docs.python.org/library/getopt.html</a></p>
<p>As you can see this is pretty flexible as well as powerful, but is not really that <a href="http://faassen.n--tree.net/blog/view/weblog/2005/08/06/0">pythonic</a>.  Two better options are optparse and argparse.</p>
<p><strong>Using optparse</strong><br />
Optparse was definitely the way to go until Python 2.7 came out and still is if you are developing on systems with older (&lt;2.7) versions of Python.  Optparse does all the neat things we&#8217;ve seen with getopt in a more pythonic (and to me, more intuitive (but that might be just that I&#8217;ve been drinking the Python Kool-Aid for so long)) way.</p>
<p>Since this can get a little confusing with trivial examples, I&#8217;m going to include a snippet of some code I&#8217;ve been working on:</p>
<pre>
import optparse

usage = "usage: %prog [options]"

#Handle the commands line options
parser = optparse.OptionParser(usage=usage)
parser.add_option("-d", "--date", dest="date",
             help="Process a specific date in the format %m%d", default="today")
parser.add_option("-f", "--force", action="store_true", dest="force",
             help="Force reindex of files - overwite existing files for date", default=False)
parser.add_option("-s", "--server", dest="server",
             help="Reindex all files for a specific server (for all available dates")

(options, args) = parser.parse_args()
print "Passed Date:%s" % options.date
print "Passed Force:%s" % options.force
print "Passed Server:%s" % options.server
</pre>
<p>Here we can see how we create an OptionParser object named parser and add our options to it.  We can set default values and even tag them with usage (&#8220;help&#8221;) messages. We can then access the discrete values directly with the label we&#8217;ve assigned (ie option.date).</p>
<p>One of the coolest things is that optparse autogenerates a usage() function.  Notice that we don&#8217;t really define a function called usage, we just pass it a usage string (&#8220;In a simple case like this, I don&#8217;t think that this is even necessary) and then tag our options with help messages.</p>
<p>So if we save the above snippet as myprog3.py and run it with &#8211;help (or -h) we get the following message:</p>
<pre>
$ python myprog3.py --help
Usage: myprog3.py [options]

Options:
-h, --help                 show this help message and exit
-d DATE, --date=DATE       Process a specific date in the format %m%d
-f, --force                Force reindex of files - overwite existing files for
                           date
-s SERVER, --server=SERVER Reindex all files for a specific server (for all
                           available dates
</pre>
<p>Pretty cool. But remember, this is a deprecated module and will not be updated going forward.  If you are using Python 2.7 or greater you should use argparse.</p>
<p>Obviously there is way more that you can do with it (ie positional options, requited arguments, etc) that you can find here:<br />
<a href="http://docs.python.org/library/optparse.html%20%20">http://docs.python.org/library/optparse.html  </a></p>
<p><strong>Using argparse</strong><br />
Argparse (to me at least, I&#8217;ve not used it as much as optparse) looks to be a more streamlined version optparse, but the general gist is the same.  Usage function is handled by the library in  a similar way.  Rewriting the code that used optparse above with argparse would yeild (as myprog4.py):</p>
<pre>
import argparse

parser = argparse.ArgumentParser(description="This program process arguments")
parser.add_argument("-d", "--date", dest="date",
               help="Process a specific date in the format %%m%%d", default="today")
parser.add_argument("-f", "--force", action="store_true", dest="force",
               help="Force reindex of files - overwite existing files for date", default=False)
parser.add_argument("-s", "--server", dest="server",
               help="Reindex all files for a specific server (for all available dates")

args = parser.parse_args()
print "Passed Date:%s" % args.date
print "Passed Force:%s" % args.force
print "Passed Server:%s" % args.server
</pre>
<p>And running it we get:</p>
<pre>
H:\Code\python\examples&gt;python myprog4.py --help
usage: myprog4.py [-h] [-d DATE] [-f] [-s SERVER]

This program process arguments

optional arguments:
-h, --help                 show this help message and exit
-d DATE, --date DATE       Process a specific date in the format %m%d
-f, --force                Force reindex of files - overwite existing files for
                           date
-s SERVER, --server SERVER Reindex all files for a specific server (for all
                           available dates)
</pre>
<p>As you can see, usage is handled very similarly, the options are handled in the same way, but down in the nitty gritty details there are a lot more options then existing in optparse.  Spend some time on in the python docs to get a better understanding of all that it can do.<a href="http://docs.python.org/library/argparse.html">http://docs.python.org/library/argparse.html</a></p>
<p>Hopefully this gives you a couple more tools to use while processing command line option in Python.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seanelavelle.com/2011/08/24/command-line-processing-in-python-several-options/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why I dropped Librarything for Goodreads</title>
		<link>http://www.seanelavelle.com/2011/08/22/why-i-dropped-librarything-for-goodreads/</link>
		<comments>http://www.seanelavelle.com/2011/08/22/why-i-dropped-librarything-for-goodreads/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 10:00:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Webapps]]></category>

		<guid isPermaLink="false">http://www.seanelavelle.com/?p=28</guid>
		<description><![CDATA[I&#8217;m kind of a list-o-holic.  I love making lists of things.  A couple years ago I started looking for a why to track what I was reading on the web and the two big choices were LibraryThing.com and Goodreads.com.  I &#8230; <a href="http://www.seanelavelle.com/2011/08/22/why-i-dropped-librarything-for-goodreads/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m kind of a list-o-holic.  I love making lists of things.  A couple years ago I started looking for a why to track what I was reading on the web and the two big choices were LibraryThing.com and Goodreads.com.  I signed up for both, but I found that I liked the no-nonsense interface (even though it is pretty ugly) of Librarything better.</p>
<p>So dutifully I cataloged my books for a couple years as I read them and was pretty content.  That is until earlier this week when I tried to add the last book I read (<a href="http://www.amazon.com/Day-Armageddon-Beyond-Exile-Book/dp/B005EP1PT6/ref=sr_1_2?ie=UTF8&amp;qid=1313773553&amp;sr=8-2">Day by Day Armageddon : Beyond Exile</a> (which, while I love zombie apocalypse stories, was really rather meh)) I ran across this fun message:</p>
<p><strong>Free memberships are limited to 200 books.</strong> Upgrade to a paid membership and catalog as many books as you like. A yearly membership costs only $10.</p>
<p>Now, I&#8217;m sure that this was listed somewhere in the Terms of Service for Librarything, but I was more then a little taken by surprise.</p>
<p>I have no problem paying for web services that I use and $10 dollars is really not a lot of money, but for basically keeping a spreadsheet of what I&#8217;ve read it seemed a bit excessive.  I really didn&#8217;t use any of the &#8220;social&#8221; functions of Librarything and didn&#8217;t especially like the records for individual books.  Also the 200 limit seemed pretty low since I only added 3 years worth of books that I was actually reading and hadn&#8217;t even loaded up books that I meant to read, or owned but haven&#8217;t gotten around to reading or whatever.</p>
<p>So I started going back over my choices.  I knew about Goodreads, but I really didn&#8217;t want to lose all the 200 books that I had cataloged and tagged in Librarything.  Luckily there exists an export function in Librarything and an import from a file in Goodreads.  I found that exporting and importing as a tab delimited file (xls) seemed to work better then exporting and importing as a comma separated value file (csv). I have noticed that some of the tags apprear to be messed up, but fixing that should be no big deal.</p>
<p>I also like the fact that Goodreads provides an Android App (<a href="https://market.android.com/details?id=com.goodreads">Android Market Link</a>)</p>
<p>So long story short, I&#8217;ve ported all my books over to Goodreads and that is where you can find me now.</p>
<p>My Goodreads profile <a href="http://www.goodreads.com/user/show/1401430-sean-lavelle">http://www.goodreads.com/user/show/1401430-sean-lavelle</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.seanelavelle.com/2011/08/22/why-i-dropped-librarything-for-goodreads/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Python&#8217;s subprocess module to run piped commands</title>
		<link>http://www.seanelavelle.com/2011/08/03/using-pythons-subprocess-module-to-run-piped-commands/</link>
		<comments>http://www.seanelavelle.com/2011/08/03/using-pythons-subprocess-module-to-run-piped-commands/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 12:25:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.seanelavelle.com/?p=26</guid>
		<description><![CDATA[Python&#8217;s subprocess module is really powerful.  It gives you a way to cleanly integrate shell commands into your scripts while managing input/output in a standard way.  The one place that I&#8217;ve found that it can get tricky though is when &#8230; <a href="http://www.seanelavelle.com/2011/08/03/using-pythons-subprocess-module-to-run-piped-commands/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Python&#8217;s subprocess module is really powerful.  It gives you a way to cleanly integrate shell commands into your scripts while managing input/output in a standard way.  The one place that I&#8217;ve found that it can get tricky though is when you need to pipe one command into another.  For example, say you want to send an email using the unix mail command:</p>
<pre>$ echo "This is the subject of my email" | mail - s "My Email Title" sean@example.com</pre>
<p>(Of course you could do this though the python smtp library, but what we are interested in is the behavior of piping the echo command into the mail command).</p>
<p>Using the subprocess module,  we would would write it like this</p>
<pre>import subprocess

emailAddress = 'sean@example.com'
title = 'My Email Title'
subject = 'This is the subject of my email'

p1 = subprocess.Popen(['echo', subject], stdout=subprocess.PIPE) #Set up the echo command and direct the output to a pipe
p2 = subprocess.Popen(['mail', '-s' ,title, emailAddress], stdin=p1.stdout #send p1's output to p2
p1.stdout.close() #make sure we close the output so p2 doesn't hang waiting for more input
output = p2.communicate()[0] #run our commands</pre>
<p>Although it might seem a bit difficult at first, now that I&#8217;ve used this method for a while it make sense to me.  I&#8217;ve used it to rewrite shell scripts with six commands piping into each other and the method is the same as above.  And once you have these shell commands being run within python, you can do error handling, or more advanced processing which is difficult (at least for me) within shell.</p>
<p>As always the Python Documentation Library is your best friend for a more detailed explanation and other examples: <a href="http://docs.python.org/library/subprocess.html" target="_blank">http://docs.python.org/library/subprocess.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.seanelavelle.com/2011/08/03/using-pythons-subprocess-module-to-run-piped-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyODBC and FreeTDS : Unicode ntext problem [Solved]</title>
		<link>http://www.seanelavelle.com/2011/07/30/pyodbc-and-freetds-unicode-ntext-problem-solved/</link>
		<comments>http://www.seanelavelle.com/2011/07/30/pyodbc-and-freetds-unicode-ntext-problem-solved/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 21:24:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.seanelavelle.com/?p=18</guid>
		<description><![CDATA[While working on a script to find blocking processes on a SQL Server 2008 database, I ran across this error when I tried to execute a query: $ python find_blocking_processes.py Traceback (most recent call last): File "find_blocking_processes.py", line 77, in &#8230; <a href="http://www.seanelavelle.com/2011/07/30/pyodbc-and-freetds-unicode-ntext-problem-solved/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While working on a script to find blocking processes on a SQL Server 2008 database, I ran across this error when I tried to execute a query:</p>
<pre>$ python find_blocking_processes.py
Traceback (most recent call last):
File "find_blocking_processes.py", line 77, in &lt;module&gt;
find_blocking_processes(brokerConn)
File "find_blocking_processes.py", line 67, in find_blocking_processes
) x""").fetchall()
pyodbc.ProgrammingError: ('42000', '[42000] [FreeTDS][SQL Server]Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier. (4004) (SQLExecDirectW)')</pre>
<p>After a bit of digging, it appears that you need to tell the ODBC driver which protocol to talk to a server in. Rectifying this was pretty straight forward:</p>
<p>In the file /etc/freetds.conf I added a line to the serverconfig  stating to use the version 8.0 protocol:</p>
<pre># A typical Microsoft SQL Server 2008 configuration
[DEVDATABASE]
host = 10.10.10.100
port = 1433
tds version = 8.0</pre>
<p>Then in the file /etc/odbc.ini I added a line for the version as well:</p>
<pre>[DEVDATABASE]
Driver          = /usr/lib64/libtdsodbc.so.0
Server          = 10.10.10.100
Port            = 1433
Trace           = Yes
TraceFile       = /tmp/freetdssql-foobar.log
tds_version     = 8.0</pre>
<p>* Note the &#8216;_&#8217; in the tds_version  variable in the odbc.ini</p>
<p>After this, the database call ran like a dream.</p>
<p>These were the links that pointed me in the right direction to solve this issue and contain a little more information on the causes of this:</p>
<ul>
<li>FreeTDS Error while trying to retrieve information from an ntext field &#8211; <a href="http://www.ubuntitis.com/?p=64">http://www.ubuntitis.com/?p=64</a></li>
<li>PyODBC, UnixODBC, FreeTDS – config &#8211; <a href="http://kipb7.wordpress.com/2008/06/12/pyodbc-unixodbc-freetds-config/">http://kipb7.wordpress.com/2008/06/12/pyodbc-unixodbc-freetds-config/</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.seanelavelle.com/2011/07/30/pyodbc-and-freetds-unicode-ntext-problem-solved/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

