<?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>/home/shakir &#187; python</title>
	<atom:link href="http://www.mohdshakir.net/tag/python/feed" rel="self" type="application/rss+xml" />
	<link>http://www.mohdshakir.net</link>
	<description>My Piece Of The Web</description>
	<lastBuildDate>Fri, 16 Jul 2010 15:45:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Enable vim code (Python) auto complete</title>
		<link>http://www.mohdshakir.net/2007/12/27/enable-vim-code-python-auto-complete</link>
		<comments>http://www.mohdshakir.net/2007/12/27/enable-vim-code-python-auto-complete#comments</comments>
		<pubDate>Thu, 27 Dec 2007 00:41:03 +0000</pubDate>
		<dc:creator>shakir</dc:creator>
				<category><![CDATA[Information Insemination]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.mohdshakir.net/2007/12/27/enable-vim-code-python-auto-complete</guid>
		<description><![CDATA[Beginning version 7 of vim, it has this nice auto completion feature. It is by default however limited to words that has already been in the current workspace. To use it, simply press [ctrl] +n or [ctrl] + p key while in edit mode. For example: We can however *teach* vim to autocomplete a whole [...]]]></description>
			<content:encoded><![CDATA[<p>Beginning version 7 of vim, it has this nice auto completion feature. It is by default however limited to words that has already been in the current workspace. To use it, simply press <em>[ctrl] +n </em>or <em>[ctrl] + p</em> key while in edit mode. For example:</p>
<div align="center"><img width="384" height="259" src="http://www.mohdshakir.net/wp-content/uploads/image/200712/vim-auto-complete.png" alt="" /></div>
<p>We can however *teach* vim to autocomplete a whole bunch of other stuffs as well, by using something so called Dictionaries. With this idea we can have auto completion for Python, Ruby, PHP, Bash, and any other programming languages code.</p>
<p>For an example, let&#8217;s try to install Python dictionary, by downloading it from here:</p>
<pre>

http://www.vim.org/scripts/script.php?script_id=850
</pre>
<p>The next thing to do is to extract the downloaded file to the appropriate folder:</p>
<pre>
shakir@herugrim ~ $ mkdir ~/.vim
shakir@herugrim ~ $ tar xvzf pydiction-0.5.tar.gz -C ~/.vim
</pre>
<p>and add this lines to your ~/.vimrc (be sure to replace &quot;/home/shakir&quot; to your own home directory)</p>
<pre>
if has("autocmd")
    autocmd FileType python set complete+=k/home/shakir/.vim/pydiction-0.5/pydiction isk+=.,(
endif " has("autocmd"
</pre>
<p>and let&#8217;s see the result:</p>
<p align="center"><img width="388" height="257" src="http://www.mohdshakir.net/wp-content/uploads/image/200712/vim-auto-complete-python.png" alt="" /></p>
<p>Browse around the Vim script page and your customized Vim could be just as good if not better than some IDEs.. <img src='http://www.mohdshakir.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.mohdshakir.net/2007/12/27/enable-vim-code-python-auto-complete/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Interactive Python shell with IPython</title>
		<link>http://www.mohdshakir.net/2007/12/15/interactive-python-shell-with-ipython</link>
		<comments>http://www.mohdshakir.net/2007/12/15/interactive-python-shell-with-ipython#comments</comments>
		<pubDate>Sat, 15 Dec 2007 04:48:04 +0000</pubDate>
		<dc:creator>shakir</dc:creator>
				<category><![CDATA[Information Insemination]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.mohdshakir.net/2007/12/15/interactive-python-shell-with-ipython</guid>
		<description><![CDATA[One nice thing about Python as compared to some other scripting languages, is that it has a shell that enables us to test our Python script on the fly without needing to write a script file first It&#8217;s nice and all that, but when you&#8217;re too used to IDEs which has features such as auto [...]]]></description>
			<content:encoded><![CDATA[<p>One nice thing about Python as compared to some other scripting languages, is that it has a shell that enables us to test our Python script on the fly without needing to write a script file first</p>
<p>It&#8217;s nice and all that, but when you&#8217;re too used to IDEs which has features such as auto completion etcetera, you&#8217;ll feel like something is not right about the default python shell.</p>
<p>That changes when I come to IPython, one of the few other enhanced Python shell. The one feature I like most is the auto complete feature, which among other by using it I don&#8217;t need to remember module names, and at the same time would list and try Python modules that I&#8217;ve never heard of.</p>
<p>In Ubuntu, or debian in general, the package is called ipython, and to install it just;</p>
<pre>shakir@herugrim ~ $ sudo apt-get install ipython</pre>
<p>Can you spot the differences between this</p>
<pre>
shakir@herugrim ~ $ python
Python 2.5.1 (r251:54863, Oct  5 2007, 13:36:32)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import command
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named command
>>> import commands
>>> status, output = commands.getoutputstatus ('ls')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'getoutputstatus'
>>> status, output = commands.getstatusoutput ('ls')
>>> print output
Desktop
Documents
Music
Photos
>>>
shakir@herugrim ~ $
</pre>
<p>and this?</p>
<pre>
shakir@herugrim ~ $ ipython
Python 2.5.1 (r251:54863, Oct  5 2007, 13:36:32)
Type "copyright", "credits" or "license" for more information.

IPython 0.8.1 -- An enhanced Interactive Python.
?       -> Introduction to IPython's features.
%magic  -> Information about IPython's 'magic' % functions.
help    -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.

In [1]: import command
---------------------------------------------------------------------------
<type 'exceptions.ImportError'>           Traceback (most recent call last)

/home/shakir/<ipython console> in <module>()

<type 'exceptions.ImportError'>: No module named command

In [2]: import commands

In [3]: status, output = commands.
commands.__all__           commands.__hash__          commands.__setattr__
commands.__class__         commands.__init__          commands.__str__
commands.__delattr__       commands.__name__          commands.getoutput
commands.__dict__          commands.__new__           commands.getstatus
commands.__doc__           commands.__reduce__        commands.getstatusoutput
commands.__file__          commands.__reduce_ex__     commands.mk2arg
commands.__getattribute__  commands.__repr__          commands.mkarg

In [3]: status, output = commands.gets
commands.getstatus        commands.getstatusoutput

In [3]: status, output = commands.getstatusoutput('ls')

In [4]: print output
Desktop
Documents
Music
Photos

In [5]:
Do you really want to exit ([y]/n)? y
shakir@herugrim ~ $
</pre>
<p>I hope you can guess when did I press the [tab] key <img src='http://www.mohdshakir.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.mohdshakir.net/2007/12/15/interactive-python-shell-with-ipython/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;&#8216;BoundMetaData&#8217; is not defined&#8221; error in SQLAlchemy</title>
		<link>http://www.mohdshakir.net/2007/12/13/boundmetadata-is-not-defined</link>
		<comments>http://www.mohdshakir.net/2007/12/13/boundmetadata-is-not-defined#comments</comments>
		<pubDate>Thu, 13 Dec 2007 07:24:49 +0000</pubDate>
		<dc:creator>shakir</dc:creator>
				<category><![CDATA[Information Insemination]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[sqlalchemy]]></category>

		<guid isPermaLink="false">http://www.mohdshakir.net/2007/12/13/boundmetadata-is-not-defined</guid>
		<description><![CDATA[I get this error when creating a BoundMetaData object in SQLAlchemy 0.3.10. The fix is to just use MetaData instead of&#160; BoundMetaData. BoundMetaData is deprecated and replaced with MetaData Example code: from sqlalchemy import * db = create_engine('sqlite:///test.db') metadata = MetaData(db) """ Continue with the rest of your Python code """]]></description>
			<content:encoded><![CDATA[<p>I get this error when creating a BoundMetaData object in SQLAlchemy 0.3.10. The fix is to just use MetaData instead of&nbsp; BoundMetaData. BoundMetaData is deprecated and replaced with MetaData</p>
<p>Example code:</p>
<pre lang="python" line="1">
from sqlalchemy import *

db = create_engine('sqlite:///test.db')
metadata = MetaData(db)

"""
  Continue with the rest of your Python code
"""
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mohdshakir.net/2007/12/13/boundmetadata-is-not-defined/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Books&#8230;</title>
		<link>http://www.mohdshakir.net/2007/11/26/books</link>
		<comments>http://www.mohdshakir.net/2007/11/26/books#comments</comments>
		<pubDate>Mon, 26 Nov 2007 00:54:23 +0000</pubDate>
		<dc:creator>shakir</dc:creator>
				<category><![CDATA[Information Insemination]]></category>
		<category><![CDATA[Nerd Public Journal?]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[lpi]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.mohdshakir.net/2007/11/26/books</guid>
		<description><![CDATA[I went to One Utama MPH to get myself the last available copy of the LPI Linux Certification In A Nutshell book, to not fail my LPI 20x exam, again Though I prefer Exam Cram series more for the purpose, this book seems to be the only option that I have, as other books doesn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I went to One Utama MPH to get myself the last available copy of the LPI Linux Certification In A Nutshell book, to not fail my LPI 20x exam, again <img src='http://www.mohdshakir.net/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  Though I prefer Exam Cram series more for the purpose, this book seems to be the only option that I have, as other books doesn&#8217;t cover LPIC 2 exams. I&#8217;ve also bought the CSS book just to add to my Pocket Reference series of collection.</p>
<p align="center"><img width="480" height="360" alt="" src="http://www.mohdshakir.net/wp-content/uploads/image/200711/lpi-in-a-nutshell-css(1).jpg" /></p>
<p>Though I&#8217;m not into it,&nbsp; <a href="http://www.examcram2.com/title/0789731274">LPIC 1 Exam Cram 2</a> was also not available. I blame <a href="http://foss.org.my/projects/lpi/">Ditesh</a> for the shortage <img src='http://www.mohdshakir.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I was also looking for <a href="http://www.oreilly.com/catalog/pythoncook/">Python Cookbook</a>, and Django or Pylons books, but they were all not on the shelves. With this I pledge anyone who has these books to come forward and help me with that, haha.</p>
<p># The LPI manual provided by the <a href="https://savannah.nongnu.org/projects/lpi-manuals/">savannah</a> project doesn&#8217;t really cover LPI syllabus, and so if you&#8217;re planning to pass your LPI exams, don&#8217;t just rely on them. Experience speaks <img src='http://www.mohdshakir.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p># There was only 7 Python books at One Uutama MPH by the time I was there. How sad.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mohdshakir.net/2007/11/26/books/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;DeprecationWarning: SessionMiddleware is moving to beaker.middleware in 0.8&#8243; error in (K)Ubuntu</title>
		<link>http://www.mohdshakir.net/2007/11/14/deprecationwarning-sessionmiddleware-is-moving-to-beakermiddleware-in-08-error-in-kubuntu</link>
		<comments>http://www.mohdshakir.net/2007/11/14/deprecationwarning-sessionmiddleware-is-moving-to-beakermiddleware-in-08-error-in-kubuntu#comments</comments>
		<pubDate>Wed, 14 Nov 2007 08:55:24 +0000</pubDate>
		<dc:creator>shakir</dc:creator>
				<category><![CDATA[Information Insemination]]></category>
		<category><![CDATA[kubuntu]]></category>
		<category><![CDATA[pylons]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.mohdshakir.net/2007/11/14/deprecationwarning-sessionmiddleware-is-moving-to-beakermiddleware-in-08-error-in-kubuntu</guid>
		<description><![CDATA[I&#8217;ve been getting this error when running paster for my Pylons project: shakir@herugrim ~/Misc/workspace $ paster serve –reload development.ini Starting subprocess with file monitor /var/lib/python-support/python2.5/pylons/wsgiapp.py:249: DeprecationWarning: SessionMiddleware is moving to beaker.middleware in 0.8 app = SessionMiddleware(app, config.global_conf, **config.app_conf) /var/lib/python-support/python2.5/pylons/wsgiapp.py:254: DeprecationWarning: CacheMiddleware is moving to beaker.middleware in 0.8 app = CacheMiddleware(app, config.global_conf, **config.app_conf) Starting server in [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been getting this error when running paster for my Pylons project:</p>
<pre><font size="3" color="#808080">
shakir@herugrim ~/Misc/workspace $ paster serve –reload development.ini
Starting subprocess with file monitor
/var/lib/python-support/python2.5/pylons/wsgiapp.py:249: DeprecationWarning: SessionMiddleware is moving to beaker.middleware in 0.8
  app = SessionMiddleware(app, config.global_conf, **config.app_conf)
/var/lib/python-support/python2.5/pylons/wsgiapp.py:254: DeprecationWarning: CacheMiddleware is moving to beaker.middleware in 0.8
  app = CacheMiddleware(app, config.global_conf, **config.app_conf)
Starting server in PID 8550.
serving on 0.0.0.0:5000 view at http://127.0.0.1:5000
</font></pre>
<p>On my quest to solving it, I uninstall Pylons (its whole bunch of dependencies);</p>
<pre><font size="3" color="#808080">sudo apt-get remove python-pylons</font></pre>
<p>and install it back again, but this time using easy_install;</p>
<pre><font size="3" color="#808080">sudo easy_install Pylons</font></pre>
<p>Yeay, I&#8217;m now good to proceed. Happy coding to me <img src='http://www.mohdshakir.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.mohdshakir.net/2007/11/14/deprecationwarning-sessionmiddleware-is-moving-to-beakermiddleware-in-08-error-in-kubuntu/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prefix WhoIs in Python</title>
		<link>http://www.mohdshakir.net/2007/11/10/prefix-whois-in-python</link>
		<comments>http://www.mohdshakir.net/2007/11/10/prefix-whois-in-python#comments</comments>
		<pubDate>Sat, 10 Nov 2007 01:00:09 +0000</pubDate>
		<dc:creator>shakir</dc:creator>
				<category><![CDATA[Information Insemination]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.mohdshakir.net/2007/11/10/prefix-whois-in-python</guid>
		<description><![CDATA[Part of a project I&#8217;m into requires me to dig for some details on IP addresses. Normal whois query (default to whois.apnic.net) don&#8217;t give me the information that I really need for, and upon searching I came to the Prefix Whois Project. They have came up with whob, and from the website I get to [...]]]></description>
			<content:encoded><![CDATA[<p>Part of a project I&#8217;m into requires me to dig for some details on IP addresses. Normal <font face="Courier New" color="#99ccff">whois</font> query (default to <font face="Courier New" color="#99ccff">whois.apnic.net</font>) don&#8217;t give me the information that I really need for, and upon searching I came to the <a href="http://pwhois.org">Prefix Whois Projec</a>t. They have came up with <font face="Courier New" color="#99ccff">whob,</font> and from the website I get to know that I can even get part of <font face="Courier New" color="#99ccff">whob</font>&#8216;s functionality by just to query for whois from their server. Let&#8217;s try with our favorite&#8217;s TMNut Screamyx DNS</p>
<p>&nbsp;</p>
<pre>
shakir@herugrim ~ $ whois -h whois.pwhois.org 202.188.0.133
IP: 202.188.0.133
Origin-AS: 4788
Prefix: 202.188.0.0/19
AS-Path: 6079 4788
AS-Org-Name:
Org-Name: Asia Pacific Network Information Centre
Net-Name: APNIC-CIDR-BLK
Cache-Date: 1195082506
Latitude: 3.167000
Longitude: 101.700000
City: -
Region: -
Country: MALAYSIA
</pre>
<p>I&#8217;ve just started to learn, and like Python, and let&#8217;s see  my Python example to extract the whois info;</p>
<pre  lang="python" line="1">import commands

def main():

    whoisServer = "whois.pwhois.org"
    IPAddr = "202.188.0.133"

    status, output = commands.getstatusoutput('whois -h ' + whoisServer + " " + IPAddr)

    result = {}

    for i in output.splitlines():
        stripped = i.split(':')
        result[stripped[0]] = stripped[1]

    print result

if __name__ == "__main__":
    main()
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.mohdshakir.net/2007/11/10/prefix-whois-in-python/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
