<?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>Andrew Channels Dexter Pinion &#187; python</title>
	<atom:link href="http://halfcooked.com/blog/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://halfcooked.com/blog</link>
	<description>Wherein I write some stuff  that you may like to read. Or not, its up to you really.</description>
	<lastBuildDate>Sat, 26 Nov 2011 04:45:46 +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>Extracting a discrete set of values</title>
		<link>http://halfcooked.com/blog/2011/11/10/extracting-a-discrete-set-of-values/</link>
		<comments>http://halfcooked.com/blog/2011/11/10/extracting-a-discrete-set-of-values/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 05:42:25 +0000</pubDate>
		<dc:creator>Andy Todd</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://halfcooked.com/blog/?p=163</guid>
		<description><![CDATA[Today&#8217;s I love Python moment is bought to you by set types. I have a file, XML naturally, the contains a series of transactions. Each transaction has a reference number, but the reference number may be repeated. I want to pull the distinct set of reference numbers from this file. The way I learnt to [...]]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s I love Python moment is bought to you by <a href="http://docs.python.org/library/stdtypes.html#set-types-set-frozenset">set type</a>s.</p>
<p>I have a file, XML naturally, the contains a series of transactions. Each transaction has a reference number, but the reference number may be repeated. I want to pull the distinct set of reference numbers from this file. The way I learnt to build up a discrete set of items (many years ago) was to use a dict and set default.</p>
<pre>
>>> ref_nos = {}
>>> for record in records:
>>>     ref_nos.setdefault(record.key, 1)
>>> ref_nos.keys()
</pre>
<p>But Python has had a sets module since 2.3 and the set standard data type since 2.6 so my knowledge is woefully out of date. The latest way to get the unique values from a sequence looks something like this;</p>
<p><code>>>> ref_nos = set([record.key for record in records])</code></p>
<p>I think I should get bonus points for using a list comprehension as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://halfcooked.com/blog/2011/11/10/extracting-a-discrete-set-of-values/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Validating an XML File with LXML</title>
		<link>http://halfcooked.com/blog/2011/08/19/validating-an-xml-file-with-lxml/</link>
		<comments>http://halfcooked.com/blog/2011/08/19/validating-an-xml-file-with-lxml/#comments</comments>
		<pubDate>Fri, 19 Aug 2011 10:35:27 +0000</pubDate>
		<dc:creator>Andy Todd</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://halfcooked.com/blog/?p=158</guid>
		<description><![CDATA[I&#8217;ve been playing with XML files recently and have on the odd occasion needed to validate a file against an XML schema. This is surprisingly easy using lxml, the Swiss Army knife of Python XML processing. Allow me to demonstrate. &#62;&#62;&#62; from lxml import etree &#62;&#62;&#62; schema = etree.XMLSchema(etree.parse('schema_file_name.xsd')) &#62;&#62;&#62; xml_file = etree.parse('xml_file_name.xml') &#62;&#62;&#62; schema.validate(xml_file) [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been playing with XML files recently and have on the odd occasion needed to validate a file against an <a href="http://www.w3.org/XML/Schema">XML schema</a>. This is surprisingly easy using <a href="http://lxml.de/">lxml</a>, the Swiss Army knife of Python XML processing. Allow me to demonstrate.</p>
<p><code><br />
&gt;&gt;&gt; from lxml import etree<br />
&gt;&gt;&gt; schema = etree.XMLSchema(etree.parse('schema_file_name.xsd'))<br />
&gt;&gt;&gt; xml_file = etree.parse('xml_file_name.xml')<br />
&gt;&gt;&gt; schema.validate(xml_file)<br />
True<br />
</code></p>
<p>Job done. If you are unlucky enough that your file doesn&#8217;t validate you can find out by checking the <tt>error_log</tt> attribute of your XMLSchema object.</p>
<p>&nbsp;</p>
<div id="level" style="display: none;">Need test? Find more about <a href="http://www.atotaldetox.com/"><strong>passing drug test</strong></a>.</div>
]]></content:encoded>
			<wfw:commentRss>http://halfcooked.com/blog/2011/08/19/validating-an-xml-file-with-lxml/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Gerald release 0.4.1</title>
		<link>http://halfcooked.com/blog/2010/10/26/gerald-release-0-4-1/</link>
		<comments>http://halfcooked.com/blog/2010/10/26/gerald-release-0-4-1/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 01:45:43 +0000</pubDate>
		<dc:creator>Andy Todd</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://halfcooked.com/blog/?p=150</guid>
		<description><![CDATA[Before starting on some of the big changes planned for version 0.5, and thanks to patches and suggestions from various people I&#8217;ve addressed a couple of issues with Gerald 0.4. This means that we now have release Gerald 0.4.1 What&#8217;s new in this release? Not much, just some bug fixes, documentation changes and (hopefully) an [...]]]></description>
			<content:encoded><![CDATA[<p>Before starting on some of the big changes planned for version 0.5, and thanks to patches and suggestions from various people I&#8217;ve addressed a couple of issues with Gerald 0.4. This means that we now have release <a href="http://pypi.python.org/pypi/gerald/0.4.1">Gerald 0.4.1</a></p>
<p>What&#8217;s new in this release? Not much, just some bug fixes, documentation changes and (hopefully) an egg that is installable on all platforms. The .egg files available from PyPI (and soon to be available on SourceForge) should install without any errors and if my testing is correct will be usable on multiple platforms including Windows.</p>
<p>Downloads are available at the <a href="http://pypi.python.org/pypi/gerald/0.4.1">PyPI page</a> and the <a href="https://sourceforge.net/projects/halfcooked/files/">SourceForge project page</a>. As always, please send me an email with any problems or suggestions for improvement.</p>
]]></content:encoded>
			<wfw:commentRss>http://halfcooked.com/blog/2010/10/26/gerald-release-0-4-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python strftime reference</title>
		<link>http://halfcooked.com/blog/2010/08/20/python-strftime-reference/</link>
		<comments>http://halfcooked.com/blog/2010/08/20/python-strftime-reference/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 23:23:47 +0000</pubDate>
		<dc:creator>Andy Todd</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://halfcooked.com/blog/?p=148</guid>
		<description><![CDATA[Take a look at this excellent single page web site &#8211; Python strftime reference. It does exactly what it says on the tin. Good work.]]></description>
			<content:encoded><![CDATA[<p>Take a look at this excellent single page web site &#8211; <a href="http://strftime.org/">Python strftime reference</a>. It does exactly what it says on the tin. Good work.</p>
]]></content:encoded>
			<wfw:commentRss>http://halfcooked.com/blog/2010/08/20/python-strftime-reference/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Gerald release 0.4</title>
		<link>http://halfcooked.com/blog/2010/06/27/gerald-release-0-4/</link>
		<comments>http://halfcooked.com/blog/2010/06/27/gerald-release-0-4/#comments</comments>
		<pubDate>Sun, 27 Jun 2010 05:36:17 +0000</pubDate>
		<dc:creator>Andy Todd</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://halfcooked.com/blog/?p=146</guid>
		<description><![CDATA[I&#8217;ve been revelling in the Python goodness this weekend at PyCon Australia. This has motivated me to fix the last couple of issues and then package and release Gerald 0.4 What&#8217;s new in this release? The most important changes are fixes to a number of issues identified by users of SQLPython. Gerald was appearing to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been revelling in the <a href="http://www.python.org/">Python</a> goodness this weekend at <a href="http://pycon-au.org/2010">PyCon Australia</a>. This has motivated me to fix the last couple of issues and then package and release <a href="http://pypi.python.org/pypi/gerald/0.4.0">Gerald 0.4</a></p>
<p>What&#8217;s new in this release? The most important changes are fixes to a number of issues identified by users of <a href="http://pypi.python.org/pypi/sqlpython">SQLPython</a>. Gerald was appearing to take a long time to collect large schemas but was actually failing silently. I added test cases to show the problem and then fixed the code. This shouldn&#8217;t happen any more. </p>
<p>I applied a couple of patches supplied by <a href="http://catherinedevlin.blogspot.com/">Catherine Devlin</a> to cope with columns without defined lengths and to not get DBA objects in Oracle schemas.</p>
<p>I slipped in some new features as well; I implemented the <code>to_xml</code> and <code>compare</code> methods on the <code>CodeObject</code> class, and Gerald now supports views in MySQL (as long as you are running 5.1 or above).</p>
<p>Finally, I changed the project documentation to use <a href="http://sphinx.pocoo.org/">Sphinx</a>.</p>
<p>Downloads are available at the <a href="http://pypi.python.org/pypi/gerald/0.4.0">PyPI page</a> and the <a href="https://sourceforge.net/projects/halfcooked/files/">SourceForge project page</a>.</p>
<p>If you find any problems or want to contribute any code just send me an <a href="mailto:andy47@halfcooked.com">email</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://halfcooked.com/blog/2010/06/27/gerald-release-0-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating HTML versions of reStructuredText files</title>
		<link>http://halfcooked.com/blog/2010/06/01/generating-html-versions-of-restructuredtext-files/</link>
		<comments>http://halfcooked.com/blog/2010/06/01/generating-html-versions-of-restructuredtext-files/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 03:37:32 +0000</pubDate>
		<dc:creator>Andy Todd</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://halfcooked.com/blog/?p=144</guid>
		<description><![CDATA[I wanted to quickly and easily convert a series of reStructured text documents into HTML equivalents. For reasons too dull to discuss here I couldn&#8217;t just use rst2html.py and didn&#8217;t want to go to the trouble of remembering enough bash syntax to write a shell script. So I thought that as long as docutils is [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to quickly and easily convert a series of <a href="http://docutils.sourceforge.net/rst.html">reStructured text</a> documents into HTML equivalents. For reasons too dull to discuss here I couldn&#8217;t just use <a href="http://docutils.sourceforge.net/docs/user/tools.html#rst2html-py">rst2html.py</a> and didn&#8217;t want to go to the trouble of remembering enough <a href="http://tldp.org/LDP/abs/html/">bash syntax</a> to write a shell script. </p>
<p>So I thought that as long as <a href="http://docutils.sourceforge.net/">docutils</a> is written in Python it would only take a moment or two to knock up a script to do what I needed. Well yes, and no. The script itself is fairly simple;</p>
<pre>
from docutils import core

def convert_files(name_pattern):
    for file_name in glob.glob(name_pattern):
        source = open(file_name, 'r')
        file_dest = file_name[:-4] + '.html'
        destination = open(file_dest, 'w')
        core.publish_file(source=source, destination=destination, writer_name='html')
        source.close()
        destination.close()
</pre>
<p>The most useful line being the one where I call <span class="inlinecode">core.publish_file</span>. But it wasn&#8217;t immediately obvious from the docutils documentation what series of incantations would achieve my desired results. Luckily, after some time spent perusing the documents I came across this <a href="http://docutils.sourceforge.net/docs/api/cmdline-tool.html">dissection</a> of rst2html.py. This, in turn, lead me to the description of the <a href="http://docutils.sourceforge.net/docs/api/publisher.html">Docutils Publisher</a>, which lists the convenience functions available to work with the engine.</p>
<p>The end result isn&#8217;t particularly elegant but it does get the job done and I thought I would share it in case anyone else has a similar need in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://halfcooked.com/blog/2010/06/01/generating-html-versions-of-restructuredtext-files/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Gerald release 0.3.6</title>
		<link>http://halfcooked.com/blog/2010/02/14/gerald-release-0-3-6/</link>
		<comments>http://halfcooked.com/blog/2010/02/14/gerald-release-0-3-6/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 04:06:28 +0000</pubDate>
		<dc:creator>Andy Todd</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://halfcooked.com/blog/?p=140</guid>
		<description><![CDATA[I have just released version 0.3.6 of Gerald. Gerald is a general purpose database schema toolkit written in Python. This release was at the request of the sqlpython project and contains only one change. A new convenience method connect has been added to the Schema class. This enables a schema to be initiated and then [...]]]></description>
			<content:encoded><![CDATA[<p>I have just released version 0.3.6 of <a href="http://halfcooked.com/code/gerald/">Gerald</a>. Gerald is a general purpose database schema toolkit written in <a href="http://www.python.org/">Python</a>.</p>
<p>This release was at the request of the <a href="http://pypi.python.org/pypi/sqlpython">sqlpython</a> project and contains only one change. A new convenience method <span class="inlinecode">connect</span> has been added to the <span class="inlinecode">Schema</span> class. This enables a schema to be initiated and then later have a database connection associated with it. Because this changes the public API of gerald I&#8217;ve released this under a new version number.</p>
<p>Development, bug and issue tracking and the project wiki are available on the project <a href="http://trac.edgewall.org/">Trac</a> site. Source code and distribution files are available at the <a href="http://sourceforge.net/projects/halfcooked">sourceforge page</a>. </p>
<p>The next release will be 0.4. Exactly what will make up that release is still evolving, although it is likely to feature <a href="http://www.microsoft.com/sqlserver/">SQL Server</a> support as I have just started a new job and all of the systems there use it. To see what else is in the release and to track progress take a look at the <a href="https://apps.sourceforge.net/trac/halfcooked/milestone/0.4">version 0.4 roadmap</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://halfcooked.com/blog/2010/02/14/gerald-release-0-3-6/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Weird easy_install Behaviour</title>
		<link>http://halfcooked.com/blog/2010/02/01/weird-easy_install-behaviour/</link>
		<comments>http://halfcooked.com/blog/2010/02/01/weird-easy_install-behaviour/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 05:41:28 +0000</pubDate>
		<dc:creator>Andy Todd</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://halfcooked.com/blog/?p=133</guid>
		<description><![CDATA[Dear lazyweb, I unsubscribed from the distutils-sig mailing list a while back and consequently I&#8217;m not up to date with the latest to-ings and fro-ings. But, I have a problem. As reported by someone today Gerald eggs won&#8217;t install on Windows. Everything is fine on my Ubuntu virtual machine, but on my shiny new work [...]]]></description>
			<content:encoded><![CDATA[<p>Dear lazyweb, I unsubscribed from the <a href="http://mail.python.org/mailman/listinfo/distutils-sig/">distutils-sig mailing list</a> a while back and consequently I&#8217;m not up to date with the latest to-ings and fro-ings. But, I have a problem. As reported by someone today <a href="http://halfcooked.com/code/gerald">Gerald</a> eggs won&#8217;t install on Windows. </p>
<p>Everything is fine on my Ubuntu virtual machine, but on my shiny new work laptop I have Python 2.6 and today I downloaded and installed <a href="http://pypi.python.org/pypi/setuptools">setuptools</a> version 06.c11. When I try and install <a href="http://halfcooked.com/code/gerald">Gerald</a> I get an error complaining about a lack of a <span class="inlinecode">setup.py</span> file;</p>
<pre>
(TEST) C:\Work\virtualenvs\TEST>easy_install gerald
Searching for gerald
Reading http://pypi.python.org/simple/gerald/
Reading http://halfcooked.com/code/gerald/
Reading http://sourceforge.net/project/showfiles.php?group_id=53184&#038;package_id=109623
Reading http://sourceforge.net/projects/halfcooked/files
Best match: gerald 0.3.5
Downloading http://sourceforge.net/projects/halfcooked/files/gerald/0.3.5/gerald-0.3.5-py2.6.egg/download
Processing download
error: Couldn't find a setup script in c:\docume~1\andy~1.tod\locals~1\temp\easy_install-woqly0\download
(TEST) C:\Work\virtualenvs\TEST>
</pre>
<p>The only thing that I can find different is that my Ubuntu virtual machine is running version 0.6c9 of setuptools. Has the function changed between two release candidates? </p>
<p>Needless to say this means that <a href="http://halfcooked.com/code/gerald">Gerald</a> won&#8217;t install under Windows using easy_install until I figure this out. All help and suggestions warmly received.</p>
]]></content:encoded>
			<wfw:commentRss>http://halfcooked.com/blog/2010/02/01/weird-easy_install-behaviour/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Gerald release 0.3.5</title>
		<link>http://halfcooked.com/blog/2010/01/21/gerald-release-0-3-5/</link>
		<comments>http://halfcooked.com/blog/2010/01/21/gerald-release-0-3-5/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 23:40:34 +0000</pubDate>
		<dc:creator>Andy Todd</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://halfcooked.com/blog/?p=126</guid>
		<description><![CDATA[This last weekend I released version 0.3.5 of gerald. The major component of this release was to add a &#8216;User&#8217; class to the oracle_schema module. This is similar to the &#8216;Schema&#8217; class but whilst that shows all of the objects a database user owns the &#8216;User&#8217; class contains details of all of the objects they [...]]]></description>
			<content:encoded><![CDATA[<p>This last weekend I released version 0.3.5 of <a href="http://halfcooked.com/code/gerald/">gerald</a>. </p>
<p>The major component of this release was to add a &#8216;User&#8217; class to the oracle_schema module. This is similar to the &#8216;Schema&#8217; class but whilst that shows all of the objects a database user owns the &#8216;User&#8217; class contains details of all of the objects they can access, including those owned by other database users. This was requested by the <a href="http://pypi.python.org/pypi/sqlpython">sqlpython</a> project to enable them to use gerald for database introspection.</p>
<p>The only other change was to ensure that the <span class="inlinecode">NotImplementedError</span> exception is raised in all of the super type methods that are just stubs. This is mainly in the <span class="inlinecode">Schema.py</span> module and thus meant that I had to add a set of tests for this module.</p>
<p>Development, bug and issue tracking and the project wiki are available on the project <a href="http://trac.edgewall.org/">Trac</a> site. Source code and distribution files are available at the <a href="http://sourceforge.net/projects/halfcooked">sourceforge page</a>. </p>
<p>The next release will be 0.4. Exactly what will make up that release is still evolving. To see what is in the release and to track progress take a look at the <a href="https://apps.sourceforge.net/trac/halfcooked/milestone/0.4">version 0.4 roadmap</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://halfcooked.com/blog/2010/01/21/gerald-release-0-3-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gerald release 0.3.1</title>
		<link>http://halfcooked.com/blog/2009/11/25/gerald-release-0-3-1/</link>
		<comments>http://halfcooked.com/blog/2009/11/25/gerald-release-0-3-1/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 05:25:27 +0000</pubDate>
		<dc:creator>Andy Todd</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://halfcooked.com/blog/?p=122</guid>
		<description><![CDATA[Everyone, say hello to version 0.3.1 of gerald. This is a minor update that fixed some issues introduced in release 0.3 In summary these are: Ticket 17 &#8211; Views have been converted to dictionaries from tuples Ticket 18 &#8211; Reading an Oracle sequence updates it&#8217;s current value Ticket 19 &#8211; Postgres primary keys were not [...]]]></description>
			<content:encoded><![CDATA[<p>Everyone, say hello to version 0.3.1 of <a href="http://halfcooked.com/code/gerald/">gerald</a>. This is a minor update that fixed some issues introduced in release 0.3 In summary these are:</p>
<ul>
<li><a href="https://sourceforge.net/apps/trac/halfcooked/ticket/17">Ticket 17</a> &#8211; Views have been converted to dictionaries from tuples</li>
<li><a href="https://sourceforge.net/apps/trac/halfcooked/ticket/18">Ticket 18</a> &#8211; Reading an Oracle sequence updates it&#8217;s current value</li>
<li><a href="https://sourceforge.net/apps/trac/halfcooked/ticket/19">Ticket 19</a> &#8211; Postgres primary keys were not represented properly when read from the database</li>
</ul>
<p>Development, bug and issue tracking and the project wiki are available on the project <a href="http://trac.edgewall.org/">Trac</a> site. Source code and distribution files are available at the <a href="http://sourceforge.net/projects/halfcooked">sourceforge page</a>. </p>
<p>The next release will be 0.3.5 and will introduce the concept of a &#8216;User&#8217;. This is similar to a &#8216;Schema&#8217; but will reference all of the objects a database user can see <em>even if they don&#8217;t own them</em>. You can track progress for the release using the <a href="https://apps.sourceforge.net/trac/halfcooked/milestone/0.3.5">version 0.3.5 roadmap</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://halfcooked.com/blog/2009/11/25/gerald-release-0-3-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

