<?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>Java Thinking &#187; Python</title>
	<atom:link href="http://www.javathinking.com/category/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javathinking.com</link>
	<description>Java and software development related thoughts</description>
	<lastBuildDate>Thu, 02 Feb 2012 12:16:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Tagging with Appengine DataStore</title>
		<link>http://www.javathinking.com/2009/11/tagging-with-appengine-datastore/</link>
		<comments>http://www.javathinking.com/2009/11/tagging-with-appengine-datastore/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 11:54:21 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[appengine]]></category>

		<guid isPermaLink="false">http://www.javathinking.com/?p=401</guid>
		<description><![CDATA[I&#8217;ve been looking into how to implement a tagging mechanism with Appengine (Python). By using a StringListProperty, you can associate a list of tags with an entity. The model would look something like this:

from google.appengine.ext import db

class Sample(db.Model):
  name = db.StringProperty(required=True)
  tags = db.StringListProperty()

Now, assuming we want to find the entities tagged with [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I&#8217;ve been looking into how to implement a tagging mechanism with Appengine (Python). By using a StringListProperty, you can associate a list of tags with an entity. The model would look something like this:</p>
<pre>
from google.appengine.ext import db

class Sample(db.Model):
  name = db.StringProperty(required=True)
  tags = db.StringListProperty()
</pre>
<p>Now, assuming we want to find the entities tagged with a given word, we can use a query like this:</p>
<blockquote><p>
q = db.GqlQuery(&#8220;SELECT * FROM Sample where tags = :1&#8243;,&#8217;z')
</p></blockquote>
<p>If we want to find all entities that have ANY of these tags (OR) we can query with GqlQuery or filter: </p>
<blockquote><p>
q = db.GqlQuery(&#8220;SELECT * FROM Sample where tags in :1&#8243;,['a','z'])</p>
<p>q = domain.Sample.all()<br />
q.filter(&#8220;tags in &#8220;, ['b','d'])
</p></blockquote>
<p>When we want to find entities with ALL of the given tags:</p>
<blockquote><p>
q = db.GqlQuery(&#8220;SELECT * FROM Sample where tags = :1 and tags = :2&#8243;,&#8217;b',&#8217;c')<br />
q = domain.Sample.all()<br />
q.filter(&#8220;tags = &#8220;, &#8216;b&#8217;)<br />
q.filter(&#8220;tags = &#8220;, &#8216;c&#8217;)
</p></blockquote>
<p>Too easy!</p>
<p>If you have an appengine project, you can try this code out by adding the entity (Sample &#8211; listed above) to your domain model and run the following in your development console (http://localhost:8080/_ah/admin/interactive):</p>
<pre>
import domain

domain.Sample(name='t1',tags=['a','b','c']).put()
domain.Sample(name='t2',tags=['b','c','d']).put()
domain.Sample(name='t3',tags=['c','d','e']).put()
domain.Sample(name='t3',tags=['x','Y','z']).put()

def display(r):
 for r in results:
  print r.name +" tags = "+' '.join(r.tags)

print "FIND WITH THIS TAG"
q = db.GqlQuery("SELECT * FROM Sample where tags = :1",'z')
results = q.fetch(5)
display(results)

print "FIND WITH ANY OF THESE TAGS (OR)"
q = db.GqlQuery("SELECT * FROM Sample where tags in :1",['a','z'])
results = q.fetch(5)
display(results)

print "FIND WITH ANY OF THESE TAGS (OR)"
q = domain.Sample.all()
q.filter("tags in ", ['a','z'])
results = q.fetch(5)
display(results)

print "FIND WITH ANY OF THESE TAGS (AND)"
q = db.GqlQuery("SELECT * FROM Sample where tags = :1 and tags = :2",'b','c')
results = q.fetch(5)
display(results)

print "FIND WITH ALL OF THESE TAGS (AND)"
q = domain.Sample.all()
q.filter("tags = ", 'b')
q.filter("tags = ", 'c')

results = q.fetch(5)
display(results)
</pre>
<p>This should produce the following result:</p>
<blockquote><p>
FIND WITH THIS TAG<br />
t3 tags = x Y z<br />
FIND WITH ANY OF THESE TAGS (OR)<br />
t1 tags = a b c<br />
t3 tags = x Y z<br />
FIND WITH ANY OF THESE TAGS (OR)<br />
t1 tags = a b c<br />
t3 tags = x Y z<br />
FIND WITH ANY OF THESE TAGS (AND)<br />
t1 tags = a b c<br />
t2 tags = b c d<br />
FIND WITH ALL OF THESE TAGS (AND)<br />
t1 tags = a b c<br />
t2 tags = b c d
</p></blockquote>
<p>So, it&#8217;s easier than I thought. But I&#8217;m not experienced with DataStore yet, and I don&#8217;t know if there are inherit limitations with this approach &#8211; remember, there are <a href="http://code.google.com/appengine/docs/python/datastore/overview.html#Quotas_and_Limits">limits</a> on the way you retrieve data.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javathinking.com/2009/11/tagging-with-appengine-datastore/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>No module named _multiprocessing</title>
		<link>http://www.javathinking.com/2009/10/no-module-named-_multiprocessing/</link>
		<comments>http://www.javathinking.com/2009/10/no-module-named-_multiprocessing/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 10:13:03 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[appengine]]></category>

		<guid isPermaLink="false">http://www.javathinking.com/?p=395</guid>
		<description><![CDATA[I&#8217;m getting back into appengine at the moment, and I came across this error:
No module named _multiprocessing 
A google search turned up this error report:
http://code.google.com/p/googleappengine/issues/detail?id=1504
which lead to this post:
http://code.google.com/p/soc/wiki/GettingStarted

The problem was of-course, that I was using Python 2.6 instead of 2.5.
I love Linux, the solution is trivial:
The workaround for this is to install Python 2.5 [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I&#8217;m getting back into appengine at the moment, and I came across this error:</p>
<blockquote><p>No module named _multiprocessing </p></blockquote>
<p>A google search turned up this error report:</p>
<blockquote><p><a href="http://code.google.com/p/googleappengine/issues/detail?id=1504">http://code.google.com/p/googleappengine/issues/detail?id=1504</a></p></blockquote>
<p>which lead to this post:</p>
<blockquote><p><a href="http://code.google.com/p/soc/wiki/GettingStarted">http://code.google.com/p/soc/wiki/GettingStarted</a>
</p></blockquote>
<p>The problem was of-course, that I was using Python 2.6 instead of 2.5.</p>
<p>I love Linux, the solution is trivial:</p>
<blockquote><p>The workaround for this is to install Python 2.5 on your machine. It will be then be accessible by using python2.5 on the command line. Then open thirdparty/google_appengine/dev_appserver.py in your favorite text editor and replace the first line,</p>
<p>#!/usr/bin/env python</p>
<p>with</p>
<p>#!/usr/bin/env python2.5</p></blockquote>
<p>Note, I already had Python 2.5 installed via:</p>
<blockquote><p>sudo apt-get install python2.5</p></blockquote>
<p>Now, I&#8217;ll promptly get back to figuring out how best to use DataStore to implement my solution!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javathinking.com/2009/10/no-module-named-_multiprocessing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MyOnlineProfile.net launches</title>
		<link>http://www.javathinking.com/2008/08/myonlineprofilenet-launches/</link>
		<comments>http://www.javathinking.com/2008/08/myonlineprofilenet-launches/#comments</comments>
		<pubDate>Thu, 21 Aug 2008 11:20:59 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[appengine]]></category>

		<guid isPermaLink="false">http://www.javathinking.com/?p=99</guid>
		<description><![CDATA[MyOnlineProfile.net has launched &#8211; as a Google AppEngine application.
MyOnlineProfile lets you catalog your public online profiles in one place &#8211; leaving you with just one link to give your friends and one link in your email signature.
I first wrote MyOnlineProfile as a Grails application &#8211; its a small application at the moment, so it didn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><a href="http://www.myonlineprofile.net/" target="_blank">MyOnlineProfile.net</a> has launched &#8211; as a Google <a href="http://code.google.com/appengine/" target="_blank">AppEngine</a> application.</p>
<p>MyOnlineProfile lets you catalog your public online profiles in one place &#8211; leaving you with just one link to give your friends and one link in your email signature.</p>
<p>I first wrote MyOnlineProfile as a <a href="http://grails.codehaus.org/" target="_blank">Grails</a> application &#8211; its a small application at the moment, so it didn&#8217;t take long. However I did over-engineer it. I made the classic mistake of trying to solve the wrong problems and over-optimising. Luckily with being a small application and written with such a productive framework, I&#8217;m only talking about wasting hours rather than months.</p>
<p>I deployed it to my Linux VPS, but unfortunately, <a href="http://java.com" target="_blank">Java</a> based applications take up quite a bit of resources just starting up and memory on a VPS costs money (recurring money). So there just wasn&#8217;t room for it.</p>
<p>Hence re-writing it in <a href="http://python.org/" target="_blank">Python</a> for AppEngine. Being exposed to Python has been good for me &#8211; and relatively easy since <a href="http://groovy.codehaus.org/" target="_self">Groovy</a> opened my mind significantly and I was ready for the experience.</p>
<p>In addition to the language, the AppEngine environment is very much like Grails in that infrastructure is taken care of for you &#8211; just like database access is so transparent in Grails, it is in AppEngine.</p>
<p>These things make writing the application about the application rather than the technology or infrastructure &#8211; just the way I like it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.javathinking.com/2008/08/myonlineprofilenet-launches/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Prototype, JSON and Appengine</title>
		<link>http://www.javathinking.com/2008/08/prototype-json-and-appengine/</link>
		<comments>http://www.javathinking.com/2008/08/prototype-json-and-appengine/#comments</comments>
		<pubDate>Wed, 06 Aug 2008 11:20:35 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[appengine]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://www.javathinking.com/?p=95</guid>
		<description><![CDATA[I am using prototype in a Google Appengine project, and while it worked on my development machine, after deploying it onto the Google infrastructure prototype wasn&#8217;t parsing the JSON responses anymore.
In my code, I was returning the JSON in the response text (as opposed to using X-JSON response header). The Content-Type response header was set [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>I am using prototype in a Google Appengine project, and while it worked on my development machine, after deploying it onto the Google infrastructure prototype wasn&#8217;t parsing the JSON responses anymore.</p>
<p>In my code, I was returning the JSON in the response text (as opposed to using X-JSON response header). The Content-Type response header was set as application/json and my javascript code used Ajax.Request() with the parameter evalJSON:true so as to parse the response text.</p>
<p>Running locally with the dev_appserver.py everything worked okay. However when running the deployed app, the Content-Type header was no longer being set &#8211; meaning that prototype would never parse the response text.</p>
<p>I&#8217;m not sure why Content-Type doesn&#8217;t get set when running on the Google infrastructure yet it works on the development server. But, luckily when using Ajax.Request, you can specify evalJSON:&#8217;force&#8217; so that prototype parses the response regardless of the content-type.</p>
<p><strong>Server ajax response code:</strong></p>
<pre name="code" class="python">

result = func(args)
# content type doesn&#039;t work when deployed
self.response.headers.add_header(&quot;Content-Type&quot;, &#039;application/json&#039;)
self.response.out.write(simplejson.dumps(result))
</pre>
<p><strong>Javascript Ajax request:</strong></p>
<pre name="code" class="javascript">

new Ajax.Request(&#039;/rpc&#039;,{parameters:{action:&#039;add&#039;}
    ,method:&#039;post&#039;,evalJSON:&#039;force&#039;,onSuccess:function(transport) {
    var result=transport.responseJSON;
    ...
  }
}
</pre>
<p><strong>Response headers from Google:</strong></p>
<pre name="code" class="html">

Content-Type:    text/html; charset=utf-8
Cache-Control:    no-cache
Content-Encoding:    gzip
Date:    Wed, 06 Aug 2008 09:56:05 GMT
Server:    Google Frontend
Content-Length:    82
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.javathinking.com/2008/08/prototype-json-and-appengine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

