<?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>Desi Penguin’s Blog &#187; Python</title>
	<atom:link href="http://desipenguin.com/techblog/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://desipenguin.com/techblog</link>
	<description>Open source, Tech Tips, Reviews, Tutorials and more …</description>
	<lastBuildDate>Tue, 29 Jun 2010 16:38:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Reading CSV files in IronPython</title>
		<link>http://desipenguin.com/techblog/2009/07/03/reading-csv-files-in-ironpython/</link>
		<comments>http://desipenguin.com/techblog/2009/07/03/reading-csv-files-in-ironpython/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 16:13:12 +0000</pubDate>
		<dc:creator>Mandar Vaze</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[Development Tools]]></category>
		<category><![CDATA[IronPython]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://desipenguin.com/techblog/?p=294</guid>
		<description><![CDATA[



Image via Wikipedia



This is in continuation with my previous blog post :
To get IronPython to use Standard Python Modules,  one needs to add  the following two lines to C:\IronPython-2.0.1\Lib\site.py :
import sys
sys.path.append(r"C:\Python25\Lib")
While this works for most part, it doesn’t help if you are using Python extensions written in C. More about my specific problems in [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl class="wp-caption alignright" style="width: 123px;">
<dt class="wp-caption-dt"><a href="http://en.wikipedia.org/wiki/Image:CsvDelimited001.svg"><img title="stylized depiction of a csv text file" src="http://upload.wikimedia.org/wikipedia/en/thumb/3/38/CsvDelimited001.svg/113px-CsvDelimited001.svg.png" alt="stylized depiction of a csv text file" width="113" height="113" /></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image via <a href="http://en.wikipedia.org/wiki/Image:CsvDelimited001.svg">Wikipedia</a></dd>
</dl>
</div>
</div>
<p>This is in continuation with my <a href="http://desipenguin.com/techblog/2009/06/23/ironpython/" target="_blank">previous</a> blog post :</p>
<blockquote><p><span>To get <a class="zem_slink" title="IronPython" rel="homepage" href="http://www.codeplex.com/IronPython">IronPython</a> to use Standard <a class="zem_slink" title="Python (programming language)" rel="homepage" href="http://www.python.org/">Python</a> Modules,  one needs to</span> add  the following two lines to <em>C:\IronPython-2.0.1\Lib\site.py</em> :</p>
<pre>import sys
sys.path.append(r"C:\Python25\Lib")</pre>
<p>While this works for most part, it doesn’t help if you are using Python extensions written in C. More about my specific problems in another post. But there is an open source project <a href="http://code.google.com/p/ironclad/" target="_blank">IronClad</a> to deal specifically with this issue. In the meantime, you can check  <a href="http://ironpython.codeplex.com/Wiki/View.aspx?title=Differences" target="_blank">the differences between IronPython and CPython</a></p></blockquote>
<p>Reading (and writing to) <a class="zem_slink" title="Comma-separated values" rel="wikipedia" href="http://en.wikipedia.org/wiki/Comma-separated_values">CSV</a> file is critical part of my program, while in stadard python it was as easy as &#8220;import csv&#8221;, the same thing took some efforts to get it working in IronPython. I got the following error for my import statement</p>
<pre>Error on line 7 in csv.py
from functools import reduce</pre>
<p>I also tried using <a class="zem_slink" title="ActivePython" rel="wikipedia" href="http://en.wikipedia.org/wiki/ActivePython">ActiveState Python</a> 2.5.2.2 (which I already had from few months ago, didn&#8217;t feel like downloading the latest version till the problem was fixed) But that didn&#8217;t help either. With ActiveState, I got the same error on the same line, except this time it was for _csv.</p>
<p>To Quote from <a href="http://www.ironpython.info/index.php/Reading_CSV_Files" target="_blank">IronPython Cookbook</a> :</p>
<blockquote><p>For some reason the Python standard library <a class="external text" title="http://docs.python.org/lib/module-csv.html" href="http://docs.python.org/lib/module-csv.html">csv module</a> is written in C, which means that it isn&#8217;t available to IronPython.</p></blockquote>
<p>The cookbook points to a third party library called <a href="http://www.codeproject.com/KB/database/CsvReader.aspx" target="_blank">A Fast Csv Reader</a> . The cookbook has a nice example of how to use the said DLL with your IronPython Program.</p>
<p>It wasn&#8217;t clear to me as to why I had to register at Code Project to download this binary since it is provided under <a href="http://en.wikipedia.org/wiki/MIT_License" target="_blank">MIT Open Source License</a>. But whom am I gonna complain to ? Beggars can&#8217;t be choosers <img src='http://desipenguin.com/techblog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/97b6f3b5-f068-4b14-accd-9a79a802c586/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://img.zemanta.com/reblog_b.png?x-id=97b6f3b5-f068-4b14-accd-9a79a802c586" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
]]></content:encoded>
			<wfw:commentRss>http://desipenguin.com/techblog/2009/07/03/reading-csv-files-in-ironpython/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IronPython</title>
		<link>http://desipenguin.com/techblog/2009/06/23/ironpython/</link>
		<comments>http://desipenguin.com/techblog/2009/06/23/ironpython/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 17:11:23 +0000</pubDate>
		<dc:creator>Mandar Vaze</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Review]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[Development Tools]]></category>
		<category><![CDATA[IronPython]]></category>
		<category><![CDATA[Microsoft Visual Studio]]></category>

		<guid isPermaLink="false">http://desipenguin.com/techblog/?p=288</guid>
		<description><![CDATA[



Image by Michael Foord via Flickr



After working on initial prototype using pylons, on ubuntu, my employer needed a standalone application (on windows) So I was looking for ways to reuse my python code to avoid double work.  had only heard about iron python but beyond that I did not know anything more.
A bit of research [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img" style="margin: 1em; display: block;">
<div>
<dl class="wp-caption alignleft" style="width: 138px;">
<dt class="wp-caption-dt"><a href="http://www.flickr.com/photos/13483019@N00/3225539390"><img title="IronPython in Action" src="http://farm4.static.flickr.com/3428/3225539390_e512d00174_m.jpg" alt="IronPython in Action" width="128" height="160" /></a></dt>
<dd class="wp-caption-dd zemanta-img-attribution" style="font-size: 0.8em;">Image by <a href="http://www.flickr.com/photos/13483019@N00/3225539390">Michael Foord</a> via Flickr</dd>
</dl>
</div>
</div>
<p>After working on initial prototype using <a class="zem_slink" title="Pylons (web framework)" rel="homepage" href="http://www.pylonshq.com/">pylons</a>, on ubuntu, my employer needed a standalone application (on windows) So I was looking for ways to reuse my python code to avoid double work.  had only heard about iron python but beyond that I did not know anything more.</p>
<p>A bit of research later, I downloaded IronPython from <a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=IronPython" target="_blank">here</a> and<a href="http://www.codeplex.com/IronPythonStudio" target="_blank"> IronPython Studio</a>. I was quite thrilled to find out that Microsoft, has created this shell, which allows developers to integrate new languages with Visual Studio Shell.</p>
<h2>Installing IronPython Studio</h2>
<p>Installing IronPython was very straight forward. Considering it is one of the Python implementation itself, you don&#8217;t have to have standard python installed. (But I did, more on that later)</p>
<p>Setting up IronPython Studio wasn&#8217;t so straight forward.  I had to download standalone version of Visual Studio shell. But the problem, and it is well documented, is that installing the redistributable package in itself is not the complete step, as you would believe from the website. I confirmed that the package was installed, and stil IronPython Studio would complain, and refuse to proceed. It turns out that you need to install the Visual Studio environment, which is inside this directory structure you just created.</p>
<div id="attachment_290" class="wp-caption aligncenter" style="width: 613px"><img class="size-full wp-image-290" title="Visual Studio Redistributable Package " src="http://desipenguin.com/techblog/wp-content/uploads/2009/06/VS2K8-Isolated.JPG" alt="This is NOT enough" width="603" height="97" /><p class="wp-caption-text">This is NOT enough</p></div>
<div id="attachment_291" class="wp-caption aligncenter" style="width: 612px"><img class="size-full wp-image-291" title="Visual Studio Shell 2008" src="http://desipenguin.com/techblog/wp-content/uploads/2009/06/VS-Shell2K8.JPG" alt="This is what IronPython Studio needs" width="602" height="97" /><p class="wp-caption-text">This is what IronPython Studio needs</p></div>
<p>Once I installed Visual Studio Shell, IronPython Studio installed easily.  Using IronPython has been nice experience in just a few hours I have been using it. The Code completion isn&#8217;t upto my liking yet, but it is helpful at times.</p>
<h2>Using Standard Python Libraries</h2>
<p>Since my original code was written on linux, it used only the standard python modules. In a manner of speaking, it was &#8220;pure&#8221; python code. Since <em>IronPython is </em><span id="ctl00_ctl00_MasterContent_Content_wikiSourceLabel"><em>an implementation of the Python programming language running under .NET</em>, it was obivious that my code may not work as is. But I&#8217;m glad that I did not have to make too many changes to get it working under IronPython. </span></p>
<p><span>As is well documented in IronPython Tutorial, it is not very difficult to use standard python libraries with IronPython (with a few exceptions &#8211; more about this a little later) To get IronPython to use Standard Python Modules,  one needs to</span> add  the following two lines to <em>C:\IronPython-2.0.1\Lib\site.py</em> :</p>
<pre>import sys
sys.path.append(r"C:\Python25\Lib")</pre>
<p>While this works for most part, it doesn&#8217;t help if you are using Python extensions written in C. More about my specific problems  in another post. But there is an open source project <a href="http://code.google.com/p/ironclad/" target="_blank">IronClad</a> to deal specifically with this issue. In the meantime, you can check  <a href="http://ironpython.codeplex.com/Wiki/View.aspx?title=Differences" target="_blank">the differences between IronPython and CPython</a></p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 289px; width: 1px; height: 1px;">http://www.codeplex.com/IronPythonStudio</div>
<p><strong>Related articles</strong></p>
<ul>
<li><a href="http://blogs.msdn.com/hugunin/archive/2009/04/14/ironpython-in-action.aspx"> IronPython in Action </a> (blogs.msdn.com)</li>
<li><a href="http://www.mehmetalierturk.com/2009/05/04/why-python/"> Why Python? </a> (mehmetalierturk.com)</li>
</ul>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/d57dd1e2-9cff-474f-9b2e-8f575bf5d8b3/"><img class="zemanta-pixie-img" style="border: medium none ; float: right;" src="http://img.zemanta.com/reblog_b.png?x-id=d57dd1e2-9cff-474f-9b2e-8f575bf5d8b3" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script src="http://static.zemanta.com/readside/loader.js" type="text/javascript"></script></span></div>
]]></content:encoded>
			<wfw:commentRss>http://desipenguin.com/techblog/2009/06/23/ironpython/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging Python Scripts</title>
		<link>http://desipenguin.com/techblog/2008/12/24/debugging-python-scripts/</link>
		<comments>http://desipenguin.com/techblog/2008/12/24/debugging-python-scripts/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 01:57:06 +0000</pubDate>
		<dc:creator>Mandar Vaze</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[cross platform]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://desipenguin.wordpress.com/?p=108</guid>
		<description><![CDATA[Found a great way to debug python scripts interactively using pdb aka Python Debugger. It is similar to gdb used on *nix.
Essentially you import pdb in the beginning of the script, and wherever you need to start debugging, add following statement :
pdb.set_trace()
Now you execute the script from command line, and execution will stop where you [...]]]></description>
			<content:encoded><![CDATA[<p>Found a great way to debug python scripts interactively using pdb aka Python Debugger. It is similar to gdb used on *nix.<br />
Essentially you <code>import pdb</code> in the beginning of the script, and wherever you need to start debugging, add following statement :<br />
<code>pdb.set_trace()</code><br />
Now you execute the script from command line, and execution will stop where you have added set_trace() call. You are presented with pdb prompt. There after it is similar to gdb commands.</p>
<p><span id="more-108"></span>Here is the quick list of pdb commands</p>
<ul>
<li>n : Execute next line</li>
<li>s : Step inside a module</li>
<li>p : Print the value of a variable</li>
<li>c : Continue</li>
<li>l : List. Shows stack trace</li>
<li>q : Quit (Most important command <img src='http://desipenguin.com/techblog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )</li>
</ul>
<p>For details, check this <a href="http://www.ferg.org/papers/debugging_in_python.html" target="_blank">site</a></p>
<h3>But what if I can&#8217;t debug interactively ?</h3>
<p>Typically, you come across this problem when you are running the script on a server. Even if the script worked OK in test environment, in live environment something goes wrong, because the script is executed by server, and you can not control the arguments that are being passed to the script. In this scenario, you need to resort to age-old logging technique</p>
<p>Here are few line of code you need to add to your script. Modify as per your needs (especially paths)<br />
Earlier in your script (as early as possible) add following lines :<br />
<code><br />
from time import strftime<br />
f = open('D:/temp/log.txt', 'r+')<br />
f.write("-- Begin Log at %s --n" % strftime("%Y-%m-%d %H:%M:%S"))<br />
</code></p>
<p>At the end of your script (as late as possible)  add following lines :<br />
<code><br />
f.write("-- End Log at %s --n" % strftime("%Y-%m-%d %H:%M:%S"))<br />
f.close()<br />
</code></p>
<p>Your basic logging infrastructure is ready. Now you can add <code>f.write()</code> lines through out your code, as and where needed.</p>
<p><span style="color:#808080;">Note : I&#8217;m part of pythondev group on twitter.  Visit the <a href="http://twittgroups.com/group/pythondev" target="_blank">website </a>for details.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://desipenguin.com/techblog/2008/12/24/debugging-python-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My First Open Source Contribution</title>
		<link>http://desipenguin.com/techblog/2008/12/17/my-first-open-source-contribution/</link>
		<comments>http://desipenguin.com/techblog/2008/12/17/my-first-open-source-contribution/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 16:53:53 +0000</pubDate>
		<dc:creator>Mandar Vaze</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[contribution]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://desipenguin.wordpress.com/?p=80</guid>
		<description><![CDATA[SVN Plot creates variety of graphs by parsing the Subversion repository.  The Project is created by Nitin Bhide. Now he happens to be my colleague. As part of learning Python, I&#8217;ve contributed to svnplot, hosted on Google Code.
Here are my changes  
Note : I&#8217;m part of pythondev group on twitter.  Visit the website for [...]]]></description>
			<content:encoded><![CDATA[<p>SVN Plot creates variety of graphs by parsing the Subversion repository.  The Project is created by <a href="http://nitinbhide.blogspot.com/" target="_blank">Nitin Bhide</a>. Now he happens to be my colleague. As part of learning Python, I&#8217;ve contributed to <a href="http://code.google.com/p/svnplot" target="_blank">svnplot</a>, hosted on Google Code.</p>
<p><a href="http://code.google.com/p/svnplot/source/detail?r=25" target="_blank">Here </a>are my changes <img src='http://desipenguin.com/techblog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><span style="color:#808080;">Note : I&#8217;m part of pythondev group on twitter.  Visit the <a href="http://twittgroups.com/group/pythondev" target="_blank">website </a>for details.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://desipenguin.com/techblog/2008/12/17/my-first-open-source-contribution/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
