<?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>Bin-Blog &#187; python</title>
	<atom:link href="http://www.bin-co.com/blog/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bin-co.com/blog</link>
	<description>Learn about the latest in Web Development - as soon as I do.</description>
	<lastBuildDate>Tue, 13 Oct 2009 18:55:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Python Reference Manual has a lot to Learn From PHP</title>
		<link>http://www.bin-co.com/blog/2008/06/python-reference-manual-has-a-lot-to-learn-from-php/</link>
		<comments>http://www.bin-co.com/blog/2008/06/python-reference-manual-has-a-lot-to-learn-from-php/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 18:34:49 +0000</pubDate>
		<dc:creator>Binny V A</dc:creator>
				<category><![CDATA[Opinion]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[manual]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[reference]]></category>

		<guid isPermaLink="false">http://www.bin-co.com/blog/?p=110</guid>
		<description><![CDATA[
Unlike the other scripting languages I work with(like PHP, Ruby, JavaScript, etc.), I am not comfortable using Python. I have made some stuff in Python(for example, frees) &#8211; but I could get into the flow as easily as with other languages. For the longest time, I thought it was because of the whitespace issue. But [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.bin-co.com/blog/wp-content/uploads/2008/03/python-logo.gif" alt="" title="Python Logo" width="211" height="71" class="alignnone wp-image-97 intro" align="right"  /></p>
<p class="intro">Unlike the other scripting languages I work with(like PHP, Ruby, JavaScript, etc.), I am not comfortable using Python. I have made some stuff in Python(for example, <a href="http://lindesk.com/2008/04/frees-hard-disk-drives-free-space-viewer/">frees</a>) &#8211; but I could get into the flow as easily as with other languages. For the longest time, I thought it was because of the whitespace issue. But recently, I created a small Python script &#8211; that&#8217;s when I understood that whitespace does not concern me. <strong class="highlight">What make me angry at python is its documentation/manual</strong>.</p>
<p>By Python Manual, I mean the official Python Manual available at <a href="http://docs.python.org/">http://docs.python.org/</a>. I have <strong class="highlight">downloaded the entire <a href="http://www.python.org/doc/2.5.2/download/">manual to my system as HTML files</a> and use that as a reference</strong> when working with Python. This is what I have done for all the other languages I work with&#8230;</p>
<ul>
<li><a href="http://perldoc.perl.org/">Perl</a></li>
<li><a href="http://www.php.net/manual/en/">PHP</a></li>
<li><a href="http://www.ruby-doc.org/docs/ProgrammingRuby/">Ruby</a></li>
<li><a href="http://docs.sun.com/source/816-6408-10/">JavaScript</a> </li>
<li><a href="http://www.w3.org/TR/REC-CSS2/">CSS</a></li>
<li>etc.</li>
</ul>
<h2>Finding a Function</h2>
<p>There is one big problem with using HTML files as your reference &#8211; you cannot search through it. So I try to find a page in the documentation that <strong class="highlight">lists all the functions in a single page</strong>. When I need to find a function, all I have to do is <strong class="highlight">search through this page</strong>. These pages in the documentation serves this purpose&#8230;</p>
<ul>
<li><a href="http://www.php.net/manual/en/indexes.php">PHP</a></li>
<li><a href="http://perldoc.perl.org/index-functions.html">Perl</a></li>
<li><a href="http://docs.sun.com/source/816-6408-10/bklast.htm">JavaScript</a></li>
<li><a href="http://www.ruby-doc.org/docs/ProgrammingRuby/html/builtins.html">Ruby</a></li>
</ul>
<p>What about Python? Well, <strong class="highlight">Python don&#8217;t have such a page</strong> in their manual. The nearest one I could find a combination of four pages &#8211; <a href="http://docs.python.org/modindex.html">Module Index</a> + <a href="http://docs.python.org/lib/genindex.html">Library Index</a> + <a href="http://docs.python.org/tut/node19.html">Tutorial Index</a> + <a href="http://docs.python.org/ref/genindex.html">Language Index</a>. Its no where near as useful.</p>
<p>Even if you are online(remember, many people are not connected all the time), its still <strong class="highlight">not easy to find a function in Python documentation &#8211; even with searching</strong> capabilities. Don&#8217;t believe me? OK &#8211; go to <a href="http://docs.python.org/">Python Docs</a> and try to find the documentation for the function that, say, reverses an array. Now go to the <a href="http://php.net/manual/en/">PHP site</a> and do the same.</p>
<h2>Reference Formats</h2>
<p>Anyway, I cannot really complain about the the availability of the &#8216;function page&#8217;. Its just the way I prefer &#8211; other people may not want such a page. But I can complain about the fact that <strong class="highlight">they don&#8217;t provide a CHM file</strong> in their <a href="http://www.python.org/doc/2.5.2/download/">downloads section</a>. CHM solves the problem as you can search through them easily.</p>
<p>PHP, on other hand, <a href="http://www.php.net/download-docs.php">provides the CHM file</a>. This makes the PHP manual much more easier to use.</p>
<p>Even though Python don&#8217;t officially provide a CHM file, others have made it available on the net. Its just a <a href="http://www.google.com/q=python+reference+chm">google search away</a>. But I prefer to get these stuff from an official source.</p>
<h2>Level of Detail in the Documentation</h2>
<p>The worst sin of the Python manual is that the <strong class="highlight">documentation is not detailed enough</strong>. To better understand this, let&#8217;s take an example &#8211; say the array reversal function. First we take a look at the Python <a href="http://docs.python.org/lib/module-array.html#l2h-779">documentation for this function</a>&#8230;</p>
<dl>
<dt>reverse()</dt>
<dd>Reverse the order of the items in the array.</dd>
</dl>
<p>One line. That&#8217;s it! If you are not well versed in Python, you will have no idea of how to use this function &#8211; because there is no example. Most people will expect that the array must be given as the argument. But the argument list is empty in the documentation. That&#8217;s because the array is not passed as an argument &#8211; rather, in Python, this function is a member function of the array object &#8211; so the proper usage will be something like this&#8230;</p>
<pre><code class="python">x = [1,2,4]
x.reverse()
#Now x has the value [4,2,1]</code></pre>
<p>I know that because I know Python &#8211; but if a new user manages to find the documentation for this function, he will be confused. Another thing &#8211; I am not saying that there are no examples in the documentation &#8211; examples are given for a lot of functions. But its no where near the level that PHP has achieved.</p>
<p>OK &#8211; now lets see the PHP manual for the same function &#8211; <a href="http://php.net/manual/en/function.array-reverse.php">array_reverse()</a>. There is an entire page for that function. Not just for this function &#8211; there is <strong class="highlight">one page of documentation for every function</strong> in PHP. And <strong class="highlight">there are examples</strong>. And at the end, <strong class="highlight">there is a collection of &#8216;user notes&#8217;</strong> &#8211; making each function much clearer. Beautiful!</p>
<p>I feel a bit guilty about comparing Python with PHP documentation &#8211; <strong class="highlight">PHP has the best documentation in its class</strong> of languages. But still, Python has a lot to learn from PHP(I wanted to say that for a long time <img src='http://www.bin-co.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bin-co.com/blog/2008/06/python-reference-manual-has-a-lot-to-learn-from-php/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Python Hello Script</title>
		<link>http://www.bin-co.com/blog/2008/03/python-hello-script/</link>
		<comments>http://www.bin-co.com/blog/2008/03/python-hello-script/#comments</comments>
		<pubDate>Wed, 19 Mar 2008 18:01:44 +0000</pubDate>
		<dc:creator>Binny V A</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[hello]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.bin-co.com/blog/2008/03/python-hello-script/</guid>
		<description><![CDATA[
As promised in the last post(Hello Script for PHP), this is my Hello Script for Python. &#8216;Hello Script&#8216; is a file that contains the most commonly used elements of a programming language so that it can be used as a cheat sheet when working with that language.
A word of caution here &#8211; the blocks in [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://www.bin-co.com/blog/2008/03/python-hello-script/python-logo/' rel='attachment wp-att-97' title='Python Logo'><img src='http://www.bin-co.com/blog/wp-content/uploads/2008/03/python-logo.gif' alt='Python Logo' class="intro" align="right" /></a></p>
<p class="intro">As promised in the last post(<a href="http://www.bin-co.com/blog/2008/03/hello-script-for-php/">Hello Script for PHP</a>), this is my Hello Script for <a href="http://www.python.org/">Python</a>. <strong class="highlight">&#8216;<a href="http://www.bin-co.com/blog/2008/03/learning-a-new-programming-language-the-hello-world-method/">Hello Script</a>&#8216; is a file that contains the most commonly used elements of a programming language so that it can be used as a cheat sheet</strong> when working with that language.</p>
<p>A word of caution here &#8211; the blocks in Python is created using whitespace &#8211; so the indentation is important. So when you see an indentation in the below code, think of it as one tab(instead of four spaces or something).</p>
<p>I want to insert a disclaimer here &#8211; I am not that good with python. We <a href="http://www.bin-co.com/blog/2007/10/tk-verses-gtkand-python-verses-tcl/" title="	Tk Verses Gtk(And Python verses Tcl)">never really clicked</a>. I have done very limited <a href="http://www.bin-co.com/python/programs/frees/" title="Frees - PyGTK Tool to show HardDisk Space Usage">work in Python</a>. So if you notice any problems with the below script, let me know and I&#8217;ll correct it.</p>
<pre><code class="python">
#!/usr/bin/python

print "Hello World\n"

name = "Binny"
year = 2008
print "Hello, " + name + " - welcome to " + str(year) + "\n"

# If,else conditions
if (year &gt; 2008):
	print "Welcome to the future - yes, we have flying cars!\n"
elif(year &lt; 2008):
	print "The past - please don't change anything. Don't step on any butterflies. And for the sake of all thats good and holy, stay away from your parents!\n"
else:
	print "Anything wrong with your time machine? You have not gone anywhere, kiddo.\n"

# For loop
for i in range(0,3):
	print str(i) + ") Hi there!"

print ""

#Numerical Array, While
rules = ['Do no harm','Obey','Continue Living']
i = 0
while(i&lt;len(rules)):
	print "Rule " + str(i+1) + " : " + rules[i]
	i = i + 1
print ""

# Associated array, foreach
associated = {
	'hello'	:	'world',
	'foo'	:	'bar',
	'lorem'	:	'ipsum'
}
for key in associated:
	print key + " : " + associated[key]
print ""

import string
csv_values = string.split("hello,world,how,are,you\n", ",")
print string.join(csv_values, ":")

# Function, argument, return, call
def hello(name):
	return "Hello " + name + "\n"

hello_string = hello("Binny")
print hello_string

# One for the OOP fanboys - Class, members, object and stuff.
class Movie:
	name = ''
	rating = 0

	def __init__(self, name):
		self.name = name
		self.rateMovie()

	def rateMovie(self):
		self.rating = (len(self.name) % 10) + 1 #IMDBs rating algorithm. True story!

	def printMovieDetails(self):
		print "Movie : ",  self.name
		print "Rating : ", '*' * self.rating , "(", self.rating ,")\n"

#Create the object
ncfom = Movie("New Country for Old Men") #It's a sequel!
ncfom.printMovieDetails()

# File IO
# File reading, easy method...
file_in  = open('Hello.py', 'r')
contents = file_in.read()
print "Current file has " + str(len(contents)) + " chars\n"
file_in.close()
# Writing to a file
file_out = open('/tmp/hello.txt', 'w')
file_out.write("Hello World")
file_out.close()

# Command Executing
import commands
import os
print "Result of 'ls' command is " + commands.getoutput('ls') #Execute the command 'ls' and print its output
print

# Regular Expressions
import re
hell_check = re.compile("^Hell")
string = "Hello World"
if hell_check.match(string): print "Yup - its evil (Compiled)"
if re.match('^Hell', string): print "Yup - its evil (Not Compiled)"
print re.sub(r'l([^l])', r'\1', string)

</code></pre>
<p>As I said last time, save this to a file and keep it around for future reference.</p>
<p>Next hello script &#8211; Perl, Ruby or Tcl/Tk? Which one do you want &#8211; leave it in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bin-co.com/blog/2008/03/python-hello-script/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Tk Verses Gtk(And Python verses Tcl)</title>
		<link>http://www.bin-co.com/blog/2007/10/tk-verses-gtkand-python-verses-tcl/</link>
		<comments>http://www.bin-co.com/blog/2007/10/tk-verses-gtkand-python-verses-tcl/#comments</comments>
		<pubDate>Wed, 31 Oct 2007 18:29:10 +0000</pubDate>
		<dc:creator>Binny V A</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[Review]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[gui]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[pygtk]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tcl]]></category>
		<category><![CDATA[tk]]></category>

		<guid isPermaLink="false">http://www.bin-co.com/blog/2007/10/tk-verses-gtkand-python-verses-tcl/</guid>
		<description><![CDATA[Back when I was using Windows, I searched for some language that would let me create GUI application. I knew C++ &#8211; but creating a GUI using C++ was very, very hard. After some searching I found Tcl/Tk &#8211; it was perfect. I liked Tk so much that I used it to create GUI in [...]]]></description>
			<content:encoded><![CDATA[<p class="">Back when I was using Windows, I searched for some language that would let me create GUI application. I knew C++ &#8211; but creating a GUI using C++ was very, very hard. After some searching I found Tcl/Tk &#8211; it was perfect. I liked Tk so much that I used it to create <a href="http://www.bin-co.com/perl/tk/sedgui/">GUI in perl programs</a>. And <a href="http://www.bin-co.com/ruby/tk/locater/">in Ruby</a>. And in Python. I even wrote <a href="http://www.bin-co.com/tcl/tutorial/">tutorials for Tcl/Tk</a> and <a href="http://www.bin-co.com/perl/perl_tk_tutorial/">Perl/Tk</a>. Then I discovered Linux. initially I was glad that I did not choose VB &#8211; that would mean that I have to throw away all my custom programs. But since I used open languages like Tcl, Perl, Ruby etc, they will run on Linux as well.</p>
<p>But when I actually ran the programs in Linux, I got the shock of a lifetime. The applications I created looked bad &#8211; really bad&#8230;</p>
<p><img src='http://www.bin-co.com/blog/wp-content/uploads/2007/10/tk_screenshot.png' alt='TK Screenshot - Ugly' /></p>
<p>I still use many Tk programs &#8211; but because of the looks issue, I decided to stop using Tk for my new programs. So I decided to try GTK. I even created a small application using PyGTK(my first) to view the harddisk space usage in Linux &#8211; <a href="http://www.bin-co.com/python/programs/frees/">Frees</a>.</p>
<p><img src='http://www.bin-co.com/blog/wp-content/uploads/2007/10/frees_main.png' alt='Frees Screenshot' /></p>
<p>It was a very simple application &#8211; all I had to do is run the &#8216;df&#8217; command, parse its output, and display a small table using that data. I was expecting around 100, 150 lines of code at the most. But after I created the app, I have 500+ lines of code.</p>
<p>At first, I thought that it was a mistake on my part &#8211; I thought that I was not using the best method. But then I came across an <a  href="http://programming.reddit.com/info/5zagm/comments/">article in Reddit</a> &#8211; <a href="http://wiki.tcl.tk/20238">gnocl or PyGtk?</a>.</p>
<p>PyGtk is still the most recommended binding for Gtk. A lot of programs in Linux is written using PyGtk. So naturally there are a few advantages for using it&#8230;</p>
<ul>
<li>It will be the more &#8216;road-tested&#8217; binding.</li>
<li>Many system will have it installed by default.</li>
<li>Bigger community &#8211; so&#8230;
<ul>
<li>more support</li>
<li>more examples</li>
<li>more tutorials</li>
<li>etc.</li>
</ul>
</li>
</ul>
<p>One the other hand, I have to write more code.</p>
<h2>Conclusion</h2>
<p>If it is a private script &#8211; only useful for myself, then I will use Tcl/Tk or Gnometcl. If the script could be distributed, like Frees, then I will use Python GTK.</p>
<p>What about the other options&#8230;</p>
<ul>
<li>wxWidgets</li>
<li>PyQT</li>
<li>Ruby/GTK</li>
<li>Perl/GTK</li>
</ul>
<p>Any recommendations for me on which library to use? Please leave it in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bin-co.com/blog/2007/10/tk-verses-gtkand-python-verses-tcl/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
