<?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>Gray&#039;s blog &#187; python</title>
	<atom:link href="http://graysblog.org/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://graysblog.org</link>
	<description>Web Developer, Platform Coder, Coding Samurai, Person.</description>
	<lastBuildDate>Sat, 31 Jul 2010 08:54:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Python</title>
		<link>http://graysblog.org/2009/08/30/python/</link>
		<comments>http://graysblog.org/2009/08/30/python/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 06:09:23 +0000</pubDate>
		<dc:creator>Gray</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[new]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[updates]]></category>

		<guid isPermaLink="false">http://graysblog.org/?p=224</guid>
		<description><![CDATA[Alright so it&#8217;s been a while since I posted anything and I wanted to put something out there, while I have been working a lot on many projects I couldn&#8217;t really speak of, I have a few quick things to update you on before I get on to the main content:
First thing, the staff of [...]]]></description>
			<content:encoded><![CDATA[<p>Alright so it&#8217;s been a while since I posted anything and I wanted to put something out there, while I have been working a lot on many projects I couldn&#8217;t really speak of, I have a few quick things to update you on before I get on to the main content:</p>
<p>First thing, the staff of Opensock have acquired MMOCCForum, this is pretty exciting and we are going to help get that place in shape.<br />
Second, Axcid.org has had a complete rewrite of it&#8217;s API, now including keyword search. <a href="http://tunebin.info">http://tunebin.info/</a> does a great job showing this.</p>
<p>Alright now onto the main content of the post:</p>
<p>After hating python and it&#8217;s syntax for a few years, I got the push of actually LEARNING the language, including some of it&#8217;s many libraries and functions. Once you get used to it, the syntax isn&#8217;t too bad actually. It&#8217;s actually pretty easy, for example:</p>
<pre>
<div class="codesnip-container" >
<div class="python codesnip" style="font-family:monospace;"><span class="kw1">import</span> system, <span class="kw3">string</span>

<span class="st0">&quot;&quot;&quot; Python block style comments &quot;&quot;&quot;</span>
<span class="co1"># Python one line bash-style comments</span>

<span class="co1"># Rather then braces for syntax blocking, python uses whitespace</span>

<span class="co1">#Functions in python must be declared before use, unlike in javascript.</span>

<span class="co1"># The Syntax for this is def</span>

<span class="co1"># e.g.</span>

<span class="kw1">def</span> SayHello<span class="br0">&#40;</span>text<span class="br0">&#41;</span>:
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1"># This is the body of the function</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">print</span><span class="br0">&#40;</span>text<span class="br0">&#41;</span>

<span class="co1"># Say Hello would be considered a 'function alias', and would be used like this:</span>

SayHello<span class="br0">&#40;</span><span class="st0">&quot;test&quot;</span><span class="br0">&#41;</span>

<span class="co1"># Some built in python functions</span>
<span class="kw3">string</span> = <span class="st0">&quot;123&quot;</span> <span class="co1"># set a variable</span>
integer = <span class="kw2">int</span><span class="br0">&#40;</span><span class="kw3">string</span><span class="br0">&#41;</span> <span class="co1"># Convert string to integer</span>
<span class="kw3">string</span> = <span class="kw2">str</span><span class="br0">&#40;</span>integer<span class="br0">&#41;</span> <span class="co1"># Convert integer to string</span>

<span class="co1"># And block statements use : to start the block, e.g.</span>

<span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw3">string</span> = <span class="kw2">str</span><span class="br0">&#40;</span>integer<span class="br0">&#41;</span><span class="br0">&#41;</span>:
&nbsp; &nbsp; &nbsp; &nbsp; SayHello<span class="br0">&#40;</span><span class="kw2">str</span><span class="br0">&#40;</span>integer<span class="br0">&#41;</span><span class="br0">&#41;</span>

&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1"># Else if is elif</span>
&nbsp; &nbsp; &nbsp; &nbsp; 
<span class="kw1">elif</span> <span class="br0">&#40;</span><span class="kw3">string</span> = <span class="kw2">int</span><span class="br0">&#40;</span><span class="kw3">string</span><span class="br0">&#41;</span><span class="br0">&#41;</span>:
&nbsp; &nbsp; &nbsp; &nbsp; SayHello<span class="br0">&#40;</span><span class="st0">&quot;Oh..&quot;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; 
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1"># Not gonna reach this</span>

<span class="kw1">else</span>:
&nbsp; &nbsp; &nbsp; &nbsp; SayHello<span class="br0">&#40;</span><span class="st0">&quot;Else reached, so none of them was correct&quot;</span><span class="br0">&#41;</span></div>
</div>
</pre>
<p>Just for an example of python, Axcid&#8217;s new JSON api can be used like this:</p>
<pre>
<div class="codesnip-container" >
<div class="python codesnip" style="font-family:monospace;"><span class="co1"># axcid</span>
<span class="kw1">import</span> <span class="kw3">sys</span>, <span class="kw3">string</span>, <span class="kw3">urllib</span>
<span class="kw1">import</span> simplejson <span class="kw1">as</span> json

AXCID_URL=<span class="st0">&quot;http://two.axcid.org/new/api/?method=search.keyword&amp;format=json&amp;allpages=1&amp;q=&quot;</span>

<span class="kw1">def</span> GetResults<span class="br0">&#40;</span>query<span class="br0">&#41;</span>:
&nbsp; &nbsp; &nbsp; &nbsp; query = query.<span class="me1">replace</span><span class="br0">&#40;</span><span class="st0">&quot; &quot;</span>, <span class="st0">&quot;%20&quot;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; url = AXCID_URL+query
&nbsp; &nbsp; &nbsp; &nbsp; f = <span class="kw3">urllib</span>.<span class="me1">urlopen</span><span class="br0">&#40;</span>url<span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; obj = json.<span class="me1">load</span><span class="br0">&#40;</span>f<span class="br0">&#41;</span>

&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span><span class="br0">&#40;</span>obj<span class="br0">&#91;</span><span class="st0">&quot;track&quot;</span><span class="br0">&#93;</span><span class="br0">&#41;</span></div>
</div>
</pre>
<p>And the result from that:</p>
<pre>
<div class="codesnip-container" >
<div class="python codesnip" style="font-family:monospace;">results = GetResults<span class="br0">&#40;</span><span class="st0">&quot;sublime&quot;</span><span class="br0">&#41;</span>

<span class="kw1">if</span> <span class="br0">&#40;</span>results<span class="br0">&#41;</span>:
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> track <span class="kw1">in</span> results:
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">print</span><span class="br0">&#40;</span>track<span class="br0">&#91;</span><span class="st0">&quot;title&quot;</span><span class="br0">&#93;</span>+<span class="st0">&quot; - &quot;</span> + track<span class="br0">&#91;</span><span class="st0">&quot;artist&quot;</span><span class="br0">&#93;</span></div>
</div>
</pre>
<p>Writing a IRC bot in python the other day was simple as well. And a python-spidermonkey binding exists so it would be possible to bind the syntax of JS to python, <a href="http://github.com/davisp/python-spidermonkey/tree/master">Python-Spidermoney</a></p>
<p>Anyways, that&#8217;s all for my update. Hope it was useful to someone.</p>
]]></content:encoded>
			<wfw:commentRss>http://graysblog.org/2009/08/30/python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
