<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

    <title>ArunRocks (Posts tagged 'python')</title>
    <link type="application/atom+xml" href="http://www.arunrocks.com/blog/atom.xml" rel="self"/>
    <link href="http://www.arunrocks.com/"/>
    <updated>2012-01-31T22:51:33+05:30</updated>
    <id>http://www.arunrocks.com/</id>
    <author>
        <name>Arun Ravindran</name>
    </author>
    <rights>Copyright (c) 2010-2011 Arun Ravindran</rights>
    
    <entry>
        <title>Mars Rover in Python and Haskell</title>
        <link href="/blog/2010/02/01/mars-rover-in-python-and-haskell/"/>
        <updated>2010-02-01T02:02:52+05:30</updated>
        <id>http://www.arunrocks.com/blog/blog/2010/02/01/mars-rover-in-python-and-haskell</id>
        <content type="html">&lt;p&gt;Last week I tried to do something which I've been planning for quite sometime. Porting a Python program into Haskell. In case you didn't know, &lt;a href=&quot;http://www.haskell.org/&quot;&gt;Haskell&lt;/a&gt; is a purely functional programming language that's recently become a hot favourite. It has a lot of cutting edge ideas from the academic world esp laziness and strong typing. It has an interesting way to solve the 'multi-CPU problem'.&lt;/p&gt;

&lt;p&gt;Mars Rover is a famous programming problem used by &lt;a href=&quot;http://www.thoughtworks.com/&quot;&gt;Thoughtworks&lt;/a&gt; in their recruitments. I first solved the problem in Python and later attempted to solve the same in Haskell. I cannot say that I ported it from Python because the approach I've used is completely different.&lt;/p&gt;

&lt;h3&gt;The Problem&lt;/h3&gt;

&lt;blockquote&gt;&lt;p&gt;A squad of robotic rovers are to be landed by NASA on a plateau on Mars.&lt;/p&gt;

&lt;p&gt;This plateau, which is curiously rectangular, must be navigated by the rovers so that their on-board cameras can get a complete view of the surrounding terrain to send back to Earth.&lt;/p&gt;

&lt;p&gt;A rover's position and location is represented by a combination of x and y co-ordinates and a letter representing one of the four cardinal compass points. The plateau is divided up into a grid to simplify navigation. An example position might be 0, 0, N, which means the rover is in the bottom left corner and facing North.&lt;/p&gt;

&lt;p&gt;In order to control a rover , NASA sends a simple string of letters. The possible letters are 'L', 'R' and 'M'. 'L' and 'R' makes the rover spin 90 degrees left or right respectively, without moving from its current spot. 'M' means move forward one grid point, and maintain the same heading.&lt;/p&gt;

&lt;p&gt;Assume that the square directly North from (x, y) is (x, y+1).&lt;/p&gt;

&lt;p&gt;INPUT:&lt;/p&gt;

&lt;p&gt;The first line of input is the upper-right coordinates of the plateau, the lower-left coordinates are assumed to be 0,0.&lt;/p&gt;

&lt;p&gt;The rest of the input is information pertaining to the rovers that have been deployed. Each rover has two lines of input. The first line gives the rover's position, and the second line is a series of instructions telling the rover how to explore the plateau.&lt;/p&gt;

&lt;p&gt;The position is made up of two integers and a letter separated by spaces, corresponding to the x and y co-ordinates and the rover's orientation.&lt;/p&gt;

&lt;p&gt;Each rover will be finished sequentially, which means that the second rover won't start to move until the first one has finished moving.&lt;/p&gt;

&lt;p&gt;OUTPUT&lt;/p&gt;

&lt;p&gt;The output for each rover should be its final co-ordinates and heading.&lt;/p&gt;

&lt;p&gt;INPUT AND OUTPUT&lt;/p&gt;

&lt;p&gt;Test Input:&lt;/p&gt;

&lt;p&gt;5 5&lt;br/&gt;
1 2 N&lt;br/&gt;
LMLMLMLMM&lt;br/&gt;
3 3 E&lt;br/&gt;
MMRMMRMRRM&lt;/p&gt;

&lt;p&gt;Expected Output:&lt;/p&gt;

&lt;p&gt;1 3 N&lt;br/&gt;
5 1 E&lt;/p&gt;&lt;/blockquote&gt;

&lt;h3&gt;The Python solution&lt;/h3&gt;

&lt;p&gt;The Python solution is actually smaller than the problem itself. The readability isn't that great, but it is quite extensible. In fact, adding a new instruction like &lt;code&gt;B(ackward)&lt;/code&gt; would need just one additional line. You can also extend the four cardinal directions to eight with minimal changes to the code.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;    &lt;span class=&quot;n&quot;&gt;dirs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;NESW&amp;quot;&lt;/span&gt;                   &lt;span class=&quot;c&quot;&gt;# Notations for directions&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;shifts&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;# delta vector for each direction&lt;/span&gt;
    &lt;span class=&quot;c&quot;&gt;# One letter function names corresponding to each robot instruction&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;lambda&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;l&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;lambda&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;lambda&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shifts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shifts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;raw_input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;                     &lt;span class=&quot;c&quot;&gt;# Ignore the grid size&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;c&quot;&gt;# parse initial position triplet&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;dir&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;raw_input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; 
        &lt;span class=&quot;n&quot;&gt;pos&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dirs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;dir&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;c&quot;&gt;# parse instructions&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;instrns&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;raw_input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lower&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; 
        &lt;span class=&quot;c&quot;&gt;# Invoke the corresponding functions passing prev position&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;instrns&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pos&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;eval&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;si&quot;&gt;%s%s&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dirs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h3&gt;The Haskell solution&lt;/h3&gt;

&lt;p&gt;I am a beginner in Haskell, so apologies for any bad coding practices. You might notice that rather than using Reflection as in the Python code, I have used Type-inference to invoke the correct function for each instruction. Yet again, this scales well while adding new instructions.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;haskell&quot;&gt;    &lt;span class=&quot;kr&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;Data.List&lt;/span&gt;
    
    &lt;span class=&quot;n&quot;&gt;dirs&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;NESW&amp;quot;&lt;/span&gt;
    
    &lt;span class=&quot;n&quot;&gt;shifts&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;shifts&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;shifts&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;shifts&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    
    &lt;span class=&quot;n&quot;&gt;instrn&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&amp;#39;R&amp;#39;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mod&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;instrn&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&amp;#39;L&amp;#39;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mod&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;instrn&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&amp;#39;M&amp;#39;&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fst&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shifts&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;snd&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shifts&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    
    &lt;span class=&quot;n&quot;&gt;showpos&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;show&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;++&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot; &amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;++&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;show&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;++&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot; &amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;++&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dirs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!!&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;finddir&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dirchar&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;=&lt;/span&gt; 
        &lt;span class=&quot;kr&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;elemIndex&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dirchar&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dirs&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;of&lt;/span&gt;
          &lt;span class=&quot;kt&quot;&gt;Nothing&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;ne&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;invalid direction&amp;quot;&lt;/span&gt;
          &lt;span class=&quot;kt&quot;&gt;Just&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;position&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;position&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;readpos&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;kr&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;finddir&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;$&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;$&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;drop&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line3&lt;/span&gt;
                  &lt;span class=&quot;p&quot;&gt;[(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reads&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line2&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;::&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Integer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;          
                  &lt;span class=&quot;p&quot;&gt;[(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reads&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;::&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Integer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;
    
    &lt;span class=&quot;n&quot;&gt;robo&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;do&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;posn&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getLine&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;instrns&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getLine&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;putStrLn&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;showpos&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;foldl&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;instrn&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;readpos&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;posn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;instrns&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;robo&lt;/span&gt;
    
    &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;do&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;skip&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getLine&lt;/span&gt;               &lt;span class=&quot;c1&quot;&gt;-- Skip reading the grid size&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;robo&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h3&gt;Key learnings&lt;/h3&gt;

&lt;p&gt;Since some of you might be interested in Haskell, I have tried to summarize my experience in Haskell programming&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;There are no loop constructs. So everything must be done using recursion!&lt;/li&gt;
&lt;li&gt;Haskell I/O is very hard. This is because of my little knowledge of Monads. In fact, I solved the logic pretty quickly. It took me a while to figure out the input parsing.&lt;/li&gt;
&lt;li&gt;Type inference catches a lot of errors. This is quite handy but error messages are sometimes confusing&lt;/li&gt;
&lt;li&gt;I could have used Abstract Data Types for directions but it would have made the code lengthier&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;In short, programming in Haskell is a mind-bending exercise. Highly recommended!&lt;/p&gt;
</content>
    </entry>
    
    <entry>
        <title>PyCon India Talk 2009: Game Programming in Pyglet</title>
        <link href="/blog/2009/09/27/pycon-india-talk-2009-game-programming-in-pyglet/"/>
        <updated>2009-09-27T18:37:59+05:30</updated>
        <id>http://www.arunrocks.com/blog/blog/2009/09/27/pycon-india-talk-2009-game-programming-in-pyglet</id>
        <content type="html">&lt;p&gt;Thanks to everyone who enjoyed and commented on my talk today titled 'Accelerate Your Game Development with Pyglet'. I am happy to see so much enthusiasm within the python community for game development. This was my first lightning talk (and the first one for the day as well) and though, I slightly overshot the timelimit, it was a great experience.&lt;/p&gt;

&lt;p&gt;The talk was about creating a simple casual game using Pyglet called 'FruitCatch'. The source code is really small and very readable. I also compared Pyglet with Pygame and why I prefer Pyglet (in certain situations:)). The demo showed the working game in the end.&lt;/p&gt;

&lt;p&gt;You can download the &lt;a href=&quot;/downloads/pyconindia2009/fruitcatch-0.1.tar.gz&quot;&gt;game source code&lt;/a&gt; and &lt;a href=&quot;/downloads/pyconindia2009/Accelerate%20Your%20GameDevelopment%20with%20Pyglet.pdf&quot;&gt;presentation slides (PDF)&lt;/a&gt; here. I've shared this with the organisers as well, so it will be put up at the &lt;a href=&quot;http://in.pycon.org/&quot;&gt;Pycon&lt;/a&gt; site as well&lt;/p&gt;

&lt;p&gt;UPDATE: The video of the &lt;a href=&quot;http://blip.tv/file/2690880&quot;&gt;lightning talk&lt;/a&gt; is now available and has been added below:&lt;/p&gt;

&lt;!--more--&gt;


&lt;p&gt;&lt;embed src=&quot;http://blip.tv/play/AYGlulYC&quot; type=&quot;application/x-shockwave-flash&quot; width=&quot;480&quot; height=&quot;390&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot;&gt;&lt;/embed&gt;&lt;/p&gt;
</content>
    </entry>
    
    <entry>
        <title>Office Diff: An Open Source Diff for Office 2007 or 2003 documents</title>
        <link href="/blog/2009/07/21/office-diff-open-source/"/>
        <updated>2009-07-21T11:27:37+05:30</updated>
        <id>http://www.arunrocks.com/blog/blog/2009/07/21/office-diff-open-source</id>
        <content type="html">&lt;p&gt;This Saturday, I started working on something that many of my colleagues had complained about a long time ago. They work on reports all the time and most of these reports have small changes in each version. They are only interested in seeing what changed rather than read the entire report.&lt;/p&gt;

&lt;p&gt;You might suggest a lot of 'diff' tools which can do the job in either Word or Textpad. The issue was that they were working with Excel spreadsheets rather than text files and I couldn't find any free or open source solution for them. So I ended up creating a new tool called Office Diff. Interestingly, it handles not just Excel, but also all the Office 2007 and 2003 file formats plus PDF and HTML formats as well. It features an intuitive GUI interface and is completely written in Python.&lt;/p&gt;

&lt;p&gt;The next best thing was to open source it. I am using the BSD licence. I found sourceforge a good choice because they support Bazaar, my version control of choice at the moment.&lt;/p&gt;

&lt;p&gt;Please visit &lt;a href=&quot;http://officediff.sourceforge.net/&quot;&gt;Office Diff&lt;/a&gt; homepage for screenshots and check out the first release.&lt;/p&gt;
</content>
    </entry>
    
    <entry>
        <title>Workaround to Easy Install PIL on Windows</title>
        <link href="/blog/2008/08/30/workaround-to-easy-install-pil-on-windows/"/>
        <updated>2008-08-30T23:13:54+05:30</updated>
        <id>http://www.arunrocks.com/blog/blog/2008/08/30/workaround-to-easy-install-pil-on-windows</id>
        <content type="html">&lt;p&gt;This is a quick workaround for people who are using &lt;a href=&quot;http://peak.telecommunity.com/DevCenter/EasyInstall&quot;&gt;easy_install&lt;/a&gt; to install Python Imaging Library on Windows. Many people faced issues while doing this. I found a simple workaround for this.&lt;/p&gt;

&lt;p&gt;You must have tried the following&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;C:&amp;gt; easy_install PIL
Searching for PIL
...
Finished processing dependencies for PIL
C:&amp;gt; python
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on
win32
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
&amp;gt;&amp;gt;&amp;gt; import Image
Traceback (most recent call last):
  File &quot;&amp;lt;stdin&amp;gt;&quot;, line 1, in &amp;lt;module&amp;gt;
ImportError: No module named Image
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now you will need to go to your site-packages directory (typically at C:\Python\Lib\site-packages) and change one line that starts with &lt;code&gt;./PIL-1.1.6-py2.5-win32.egg&lt;/code&gt; to simply &lt;code&gt;./PIL&lt;/code&gt; and change the sub-directory named similarly to &lt;code&gt;PIL&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now your imports should work :smile:&lt;/p&gt;
</content>
    </entry>
    
    <entry>
        <title>V-day Special</title>
        <link href="/blog/2008/02/17/v-day-special/"/>
        <updated>2008-02-17T13:05:12+05:30</updated>
        <id>http://www.arunrocks.com/blog/blog/2008/02/17/v-day-special</id>
        <content type="html">&lt;p&gt;Here is a belated valentine's day greeting from both of us.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.flickr.com/photos/arun_ravindran/2270952086/&quot; title=&quot;Valentines Day by ArunClickClick, on Flickr&quot;&gt;&lt;img src=&quot;http://farm3.static.flickr.com/2301/2270952086_c28e0af5be.jpg&quot; width=&quot;500&quot; height=&quot;333&quot; alt=&quot;This photo is a macro taken by Arun&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For all my readers, I recommend visiting the &lt;a href=&quot;http://www.arunrocks.com/wedding/&quot;&gt;microsite&lt;/a&gt; I had made earlier. Now it is written entirely in &lt;a href=&quot;http://webpy.org/&quot;&gt;web.py&lt;/a&gt;. Thanks to my new website host, &lt;a href=&quot;http://refer.asmallorange.com/15934&quot;&gt;A Small Orange&lt;/a&gt;, I can create and host python based applications. I agree that there is no need to design a new blog in python again, but it is a great way to learn a new (anti-) framework. Web.py applications are really small and easy to understand and &lt;a href=&quot;http://www.paulgraham.com/head.html&quot;&gt;therefore, has less bugs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Guess what, &lt;a href=&quot;http://www.codinghorror.com/blog/archives/000624.html&quot;&gt;Jeff Atwood owns an ASUS&lt;/a&gt; laptop model (W3J) that is similar to &lt;a href=&quot;http://www.flickr.com/photos/arun_ravindran/2215166942/&quot;&gt;mine&lt;/a&gt; (F3J). He is full of praise about the decision. Considering I took at least 2 months (the standard duration for yours truly to zero into an buying decision) to arrive at the decision, it seems well worth now :).&lt;/p&gt;
</content>
    </entry>
    
    <entry>
        <title>Work Faster in Windows With Launchy and a few Python Scripts</title>
        <link href="/blog/2007/12/04/work-faster-in-windows-with-launchy-and-a-few-python-scripts/"/>
        <updated>2007-12-04T11:09:23+05:30</updated>
        <id>http://www.arunrocks.com/blog/blog/2007/12/04/work-faster-in-windows-with-launchy-and-a-few-python-scripts</id>
        <content type="html">&lt;p&gt;&lt;img src=&quot;http://farm1.static.flickr.com/133/414218839_e89ef7791d_m_d.jpg&quot; width=&quot;240&quot; height=&quot;160&quot; alt=&quot;Eating the Mouse&quot; class=&quot;alignright&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.launchy.net/&quot;&gt;Launchy&lt;/a&gt; is a great productivity tool and a cool way to impress your friends. You can launch any application by pressing a hotkey (say Alt+Space) and the first few letters of the application for eg: typing 'gi' will display the GIMP icon and pressing Enter will launch GIMP. You can &lt;a href=&quot;http://downloads.sourceforge.net/launchy/LaunchySetup125.exe?modtime=1177060449&amp;amp;big_mirror=0&quot;&gt;download Launchy&lt;/a&gt; from its website and its &lt;a href=&quot;http://www.launchy.net/LaunchySetup199_1.exe&quot;&gt;beta&lt;/a&gt; is pretty stable (and gorgeous) on my XP laptop too.&lt;/p&gt;

&lt;p&gt;Using Launchy gets pretty addictive and soon you will hate using the Start menu or even Explorer on Windows for opening applications or files. So I took the red pill and started automating the following things with a little help from Python:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Launching Intranet applications inside Internet Explorer (even if Firefox is your default browser)&lt;/li&gt;
&lt;li&gt;Bringing minimized or overlapped windows to the foreground&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Some Necessary Evil&lt;/h3&gt;

&lt;p&gt;Don't get me wrong, I hate IE as much as you do. But the fact of life is that many web apps out there &quot;Work best when viewed in IE&quot; (TM). Even if you have launchy plugins to launch the web app, if your default browser is Firefox, it might show incorrectly. Here is the solution:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install &lt;a href=&quot;http://www.python.org/download/releases/&quot;&gt;Python&lt;/a&gt; and &lt;a href=&quot;http://sourceforge.net/project/platformdownload.php?group_id=78018&quot;&gt;Pywin32&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Copy the following script to the Utilities directory (it will be in the path where you installed Launchy) and save it with a &lt;strong&gt;.pyw&lt;/strong&gt; extension not a &lt;strong&gt;.py&lt;/strong&gt; extension&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;ie.pyw:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;    &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;win32com.client&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Dispatch&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;ie&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Dispatch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;InternetExplorer.Application&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;ie&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Visible&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;ie&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Navigate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;r&amp;quot;http://intranetapp/home&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;In the above code replace the URL &lt;strong&gt;http://intranetapp/home&lt;/strong&gt; with the URL of your choice.&lt;/p&gt;

&lt;p&gt;Finally, open Launchy, right-click and say 'Rebuild Index'.&lt;/p&gt;

&lt;h3&gt;No more Alt-Tabbing around&lt;/h3&gt;

&lt;p&gt;If you are like me, you'll have a lot of windows open at the same time. I have tried increasing the task bar height and grouping similar windows feature in XP to manage them. But I always wish I could invoke commonly used open applications like my chat window in just a few keystrokes. Launchy doesn't index open programs by default, but with some python magic I can show you how to bring some commonly used windows to the foreground:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;As before, install &lt;a href=&quot;http://www.python.org/download/releases/&quot;&gt;Python&lt;/a&gt; and &lt;a href=&quot;http://sourceforge.net/project/platformdownload.php?group_id=78018&quot;&gt;Pywin32&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Copy the following script to the Utilities directory (it will be in the path where you installed Launchy) and save it with a &lt;strong&gt;.pyw&lt;/strong&gt; extension not a &lt;strong&gt;.py&lt;/strong&gt; extension&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;windowfore.pyw:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;    &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sys&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;win32gui&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GetWindowText&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EnumWindows&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ShowWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SetForegroundWindow&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;win32con&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SW_RESTORE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SW_SHOW&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;TITLE_MATCH&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Microsoft Excel - Expenses.xls&amp;quot;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;listWindowsHandles&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;res&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hwnd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;res&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hwnd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;EnumWindows&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;res&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;listWindowsNamesAndHnd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hwnd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GetWindowText&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hwnd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hwnd&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;listWindowsHandles&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()]&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;unminimizeWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a_hwnd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;ShowWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a_hwnd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SW_RESTORE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;SetForegroundWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a_hwnd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;finder1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hwnd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;title&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;listWindowsNamesAndHnd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TITLE_MATCH&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;unminimizeWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hwnd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;finder1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;In the above code change the string &lt;strong&gt;Microsoft Excel - Expenses.xls&lt;/strong&gt; with the title the window you would like to summon.&lt;/p&gt;

&lt;p&gt;Finally, open Launchy, right-click and say 'Rebuild Index'.&lt;/p&gt;

&lt;p&gt;This works even if the window was minimized.&lt;/p&gt;

&lt;p&gt;I hope, finally you can throw your mouse away. Ah... What a bliss!&lt;/p&gt;
</content>
    </entry>
    
    <entry>
        <title>Making Python Scripts Show Windows-friendly Errors/Stacktrace</title>
        <link href="/blog/2007/06/20/making-python-scripts-show-windows-friendly-errorsstacktrace/"/>
        <updated>2007-06-20T01:03:41+05:30</updated>
        <id>http://www.arunrocks.com/blog/blog/2007/06/20/making-python-scripts-show-windows-friendly-errorsstacktrace</id>
        <content type="html">&lt;p&gt;Most of us love to distribute our python programs to others once you have finished coding a neat little script. For Windows users we package it using &lt;a href=&quot;http://www.py2exe.org/index.cgi/&quot;&gt;Py2exe&lt;/a&gt; or &lt;a href=&quot;http://www.cxtools.net/default.aspx?nav=cxfrlb&quot;&gt;cx_freeze&lt;/a&gt;. However, many of the end-users will not be happy with a black command window popping up, say, when an error is thrown.&lt;/p&gt;

&lt;p&gt;Of course the alternative is to write a full blown GUI application using &lt;a href=&quot;http://www.wxpython.org/&quot;&gt;WXPython&lt;/a&gt; or &lt;a href=&quot;http://pyfltk.sourceforge.net/&quot;&gt;PyFLTK&lt;/a&gt;. Even the latter, though quite lightweight, adds several megabytes to the distribution, when all you need is a simple message-box indicating an error or showing some informational text. Clearly, its an overkill for your throwaway python scripts.&lt;/p&gt;

&lt;p&gt;This is the kind of problem I typically face and I have found a good solution. The answer is &lt;a href=&quot;http://python.net/crew/theller/ctypes/&quot;&gt;ctypes library&lt;/a&gt; which comes as a part of the standard distribution from Python 2.5 onwards. It simply calls the messagebox function from user32.dll (which is always present in a windows installation). With the main problem solved, what remained was to obtain the error text and stack trace.&lt;/p&gt;

&lt;p&gt;Let's see how the code looks like:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;    &lt;span class=&quot;c&quot;&gt;# Importing all the works for a native Win32 Message Box&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;ctypes&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c_int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;WINFUNCTYPE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;windll&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;ctypes.wintypes&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HWND&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LPCSTR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UINT&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;prototype&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;WINFUNCTYPE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c_int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HWND&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LPCSTR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LPCSTR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;UINT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;paramflags&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;hwnd&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;text&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Hi&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;caption&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;None&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;flags&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;MessageBox&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;prototype&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;MessageBoxA&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;windll&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;paramflags&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;c&quot;&gt;# For printing the stack&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sys&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;traceback&lt;/span&gt;
    &lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;time&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sleep&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;show_popup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;MessageBox&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;caption&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;Sample App Says...&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;mainloop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;Uff!&amp;quot;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;#39;__main__&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;mainloop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;except&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;nb&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;last_traceback&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exc_info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;traceback&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;format_exception&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;last_traceback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;show_popup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;Aiyooooo..... there has been an error!&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                &lt;span class=&quot;s&quot;&gt;&amp;quot;Exception in user code:&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                &lt;span class=&quot;s&quot;&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
                &lt;span class=&quot;s&quot;&gt;&amp;quot;===== Please mail a screenshot to arunvr@gmail.com ====&amp;quot;&lt;/span&gt;
                &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;finally&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;sleep&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;# show the console output for a second so that users can read it&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;&lt;em&gt;EDIT:&lt;/em&gt; This is how it looks like in PyMail, one of my scripts-that-grew-into-an-app ;)&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://i17.tinypic.com/61oz9d3.jpg&quot; alt=&quot;Screenshot of a Python Stacktrace in a Messagebox&quot; /&gt;&lt;!--12850e4e5bbcaead4138d9450f16213b--&gt;&lt;/p&gt;
</content>
    </entry>
    
    <entry>
        <title>Windows+Python Integration Like Unix shell</title>
        <link href="/blog/2005/08/12/windowspython-integration-like-unix-shell/"/>
        <updated>2005-08-12T17:29:52+05:30</updated>
        <id>http://www.arunrocks.com/blog/blog/2005/08/12/windowspython-integration-like-unix-shell</id>
        <content type="html">&lt;p&gt;Remember how in UNIX how easy it was to run &lt;a href=&quot;http://www.python.org/&quot;&gt;python&lt;/a&gt; scripts? Just type name of the script. No need to even type the extension .py&lt;/p&gt;

&lt;p&gt;I got soon fed up with typing&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;C: &amp;gt; python foo.py
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;in windows. Digging up some &lt;a href=&quot;http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx&quot;&gt;Microsoft documentation&lt;/a&gt;, I soon found a way to simply type&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;C: &amp;gt; foo
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;and make it work. How? read on...&lt;/p&gt;

&lt;p&gt;All you need is to create a batchfile, say 'startme.bat' with the two lines&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ASSOC .py=PythonScript
FTYPE PythonScript=python.exe %1 %*
set PATHEXT=.py;%PATHEXT%
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you want this to be the default behaviour everywhere, put this in 'autoexec.bat'. But wait, we have a better way to do this. You can make 'startme.bat' work like '.bashrc' in UNIX by registry hack. Create a REG file, say 'cmd-changer.reg' with the contents:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;REGEDIT4
[HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor]
&quot;AutoRun&quot;=&quot;startme.bat&quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now opening this file will merge it to the registry. Now 'startme.bat' will be run every time you open the command prompt say by typing 'cmd.exe' in the Run command box. Hope this helps!&lt;/p&gt;
</content>
    </entry>
    
    <entry>
        <title>Is Python Intellisense Possible in Emacs?</title>
        <link href="/blog/2005/06/14/is-intellisense-possible-in-emacs/"/>
        <updated>2005-06-14T20:07:17+05:30</updated>
        <id>http://www.arunrocks.com/blog/blog/2005/06/14/is-intellisense-possible-in-emacs</id>
        <content type="html">&lt;p&gt;Like the search for the Elixir of youth or &lt;a href=&quot;http://en.wikipedia.org/wiki/Alchemy&quot; title=&quot;To Wikipedia&quot;&gt;philosopher's stone&lt;/a&gt;,
I was looking for some kind of &lt;a href=&quot;http://msdn.microsoft.com/library/en-us/odc_vsto2005_ta/html/officeVSTOCodeSnippets.asp&quot; title=&quot;A Microsoft page regarding the feature&quot;&gt;Intellisense&lt;/a&gt;
feature for &lt;a href=&quot;python.org/&quot; title=&quot;Python: Language&quot;&gt;Python&lt;/a&gt; in &lt;a href=&quot;emacswiki.org/&quot; title=&quot;Emacs Wiki&quot;&gt;Emacs&lt;/a&gt; which I have grown used to since my windows
programming days. Yes I'm referring to the little drop down list
that helps you auto complete class members. I'm also referring the
tool-tip that appears which shows a functions signature when you are
calling it. I know that &lt;a href=&quot;http://www.python.org/windows/pythonwin/&quot; title=&quot;A python IDE&quot;&gt;PythonWin&lt;/a&gt;, my python editor of choice,
already does this. But I intend to use Emacs as my IDE.
It seems that you have two alternatives, both have issues
as you will see:&lt;/p&gt;

&lt;h2&gt;py-complete - Not yet Windows ready?&lt;/h2&gt;

&lt;p&gt;Firstly &lt;a href=&quot;http://cvs.sourceforge.net/viewcvs.py/python-mode/python-mode/&quot;&gt;py-complete&lt;/a&gt; seems to require &lt;a href=&quot;http://pymacs.progiciels-bpi.ca/index.html&quot; title=&quot;Allows emacs users to automate using python&quot;&gt;Pymacs&lt;/a&gt;. Now, this was
not very obvious. The idea of python helping in completion seems to be
very cool and nearly worked without pymacs. Seems pymacs is not quite
well supported in Windows. As soon as I read this I sort of gave up.&lt;/p&gt;

&lt;h2&gt;Semantic Flopped&lt;/h2&gt;

&lt;p&gt;Then, I installed &lt;a href=&quot;http://cedet.sourceforge.net/&quot; title=&quot;Collections of Emacs Development Environment Tools&quot;&gt;CEDET 1.0 (beta 3)&lt;/a&gt; which gives you &lt;a href=&quot;http://www.emacswiki.org/cgi-bin/wiki/SemanticSense&quot; title=&quot;Semantic&quot;&gt;Semantic&lt;/a&gt; inspired by this &lt;a href=&quot;http://users.binary.net/thehaas/cgi-haas/blosxom.cgi/comp/emacs/semanticandtags.html&quot;&gt;post&lt;/a&gt;. It
seemed to be a pain to install the whole thing until I discovered that
you have to keep certain things in the load-path. Finally this is what
I added to my &lt;code&gt;.emacs&lt;/code&gt; file&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;;; Set up load path
(setq load-path (append (list (concat use-home &quot;site/cedet/speedbar&quot;)
(concat use-home &quot;site/cedet/common&quot;)) load-path))
(load-file &quot;~/site/cedet/common/cedet.el&quot;) ;; Load CEDET
(semantic-load-enable-minimum-features)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now as the post suggests, we have a fully working speedbar but
auto-completion is pretty much weird. For eg: M-x
semantic-analyze-possible-completions describes the scopes you are
currently in.&lt;/p&gt;

&lt;h2&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Both approaches are really good though quite different. They haven't
made use of the emacs tool-tip library either. Since this is a
crucially lacking feature in Emacs, I might as well do a bit of R&amp;amp;D
on this before giving up the dream.&lt;/p&gt;
</content>
    </entry>
    

</feed>

