<?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>BadPopcorn &#187; Python</title>
	<atom:link href="http://badpopcorn.com/blog/category/technology/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://badpopcorn.com/blog</link>
	<description>Solutions for anything... except popcorn.</description>
	<lastBuildDate>Mon, 12 Apr 2010 15:38:15 +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>Django and Dreamhost, Take 2</title>
		<link>http://badpopcorn.com/blog/2006/11/13/django-and-dreamhost-take-2/</link>
		<comments>http://badpopcorn.com/blog/2006/11/13/django-and-dreamhost-take-2/#comments</comments>
		<pubDate>Mon, 13 Nov 2006 22:14:09 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://badpopcorn.com/2006/11/13/django-and-dreamhost-take-2/</guid>
		<description><![CDATA[After installing my own custom Python build, I went back and tweaked how Django ran on my Dreamhost account. My previous Django installation experience is still mostly valid. I just figured I could &#8220;upgrade&#8221; the installation to take advantage of Python 2.5 and eggs.
I installed three eggs to get Django running

# For Django
python ez_setup.py MySQL-python
python [...]]]></description>
			<content:encoded><![CDATA[<p>After <a href="http://badpopcorn.com/2006/10/29/python-eggs-and-dreamhost/">installing my own custom Python build</a>, I went back and tweaked how Django ran on my Dreamhost account. My <a href="http://badpopcorn.com/2005/11/30/django-is-rails/">previous Django installation experience</a> is still mostly valid. I just figured I could &#8220;upgrade&#8221; the installation to take advantage of Python 2.5 and eggs.</p>
<p>I installed three eggs to get Django running</p>
<blockquote><p>
# For Django<br />
python ez_setup.py MySQL-python<br />
python ez_setup.py http://www.saddi.com/software/flup/dist/flup-r2030.tar.gz<br />
python ez_setup.py http://www.djangoproject.com/download/0.95/tarball/
</p></blockquote>
<p>The first was mySQL support; second was for Django&#8217;s built-in <a href="http://www.djangoproject.com/documentation/fastcgi/">fcgi support</a>; and finally Django itself.</p>
<p>I had a second goal in this upgrade. I wanted to partition off the &#8220;/-/&#8221; subtree (For example, http://example.com/-/admin/) for Django, instead of using the full subdomain. I had to make a couple of changes to the project&#8217;s urls.py file (to handle the &#8216;-&#8217;) and to the .htaccess file:</p>
<blockquote><p>
# urls.py change example for the admin application.<br />
(r&#8217;^-/admin/&#8217;, include(&#8216;django.contrib.admin.urls&#8217;)),
</p></blockquote>
<p>The .htaccess file:</p>
<blockquote><p>&lt;IfModule mod_rewrite.c&gt;<br />
RewriteEngine On<br />
RewriteBase /<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteRule ^-$ /-/ [R]<br />
RewriteRule ^-/(.*)$ /_/mysite.fcgi/-/$1 [QSA,L]<br />
&lt;/IfModule mod_rewrite.c&gt;</p></blockquote>
<p>And finally, a new mysite.fcgi script found in the /_/ directory (notice that it&#8217;s an underscore, not a dash):</p>
<blockquote><p>
#!/home/user/bin/python/bin/python<br />
import sys, os</p>
<p># Switch to the directory of your project. (Optional.)<br />
# os.chdir(&#8220;/home/user/myproject&#8221;)</p>
<p># Set the DJANGO_SETTINGS_MODULE environment variable.<br />
os.environ['DJANGO_SETTINGS_MODULE'] = &#8220;myproject.settings&#8221;</p>
<p>from django.core.servers.fastcgi import runfastcgi<br />
runfastcgi(["method=threaded", "daemonize=false"])
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://badpopcorn.com/blog/2006/11/13/django-and-dreamhost-take-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python, Eggs and Dreamhost</title>
		<link>http://badpopcorn.com/blog/2006/10/29/python-eggs-and-dreamhost/</link>
		<comments>http://badpopcorn.com/blog/2006/10/29/python-eggs-and-dreamhost/#comments</comments>
		<pubDate>Sun, 29 Oct 2006 19:57:38 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://badpopcorn.com/2006/10/29/python-eggs-and-dreamhost/</guid>
		<description><![CDATA[Dreamhost, my web host, does not yet support Python2.5, and one can&#8217;t install Python eggs into Dreamhost&#8217;s own Python installations. The solution? I just installed a custom build of Python2.5 into my $HOME/opt directory. The following is the script I created to automate that process:

# Obtain Python2.5 and unpack
mkdir $HOME/downloads/
cd $HOME/downloads/
wget http://www.python.org/ftp/python/2.5/Python-2.5.tgz
tar -zxvf Python-2.5.tgz
# Creating [...]]]></description>
			<content:encoded><![CDATA[<p>Dreamhost, my web host, does not yet support Python2.5, and one can&#8217;t install Python <a href="http://peak.telecommunity.com/DevCenter/PythonEggs">eggs</a> into Dreamhost&#8217;s own Python installations. The solution? I just installed a custom build of Python2.5 into my $HOME/opt directory. The following is the script I created to automate that process:</p>
<blockquote><p>
# Obtain Python2.5 and unpack<br />
mkdir $HOME/downloads/<br />
cd $HOME/downloads/<br />
wget http://www.python.org/ftp/python/2.5/Python-2.5.tgz<br />
tar -zxvf Python-2.5.tgz</p>
<p># Creating the location under which python (and other apps) are to be installed.<br />
mkdir $HOME/opt</p>
<p># Go into the Python2.5 directory, make &#038;&#038; make install the thing<br />
cd Python-2.5<br />
./configure &#8211;prefix=$HOME/opt &#8211;enable-unicode=ucs4<br />
make &amp;&amp; make install</p>
<p># Create a bin directory for Python, and link the bin to the real executable<br />
mkdir -p $HOME/bin/python/bin<br />
ln -s $HOME/opt/bin/python $HOME/bin/python/bin/python
</p></blockquote>
<p>After the installation, I edited the bash_profile file to add the bin path:</p>
<blockquote><p>
export PATH=$HOME/bin/python/bin:$HOME/opt/bin:$PATH
</p></blockquote>
<p>Now with a custom installation of Python, I can use eggs to manage my Django projects&#8217; library dependencies. <img src='http://badpopcorn.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
]]></content:encoded>
			<wfw:commentRss>http://badpopcorn.com/blog/2006/10/29/python-eggs-and-dreamhost/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Python Conditional Expressions</title>
		<link>http://badpopcorn.com/blog/2006/09/19/python-conditional-expressions/</link>
		<comments>http://badpopcorn.com/blog/2006/09/19/python-conditional-expressions/#comments</comments>
		<pubDate>Tue, 19 Sep 2006 18:14:00 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://badpopcorn.com/2006/09/19/python-conditional-expressions/</guid>
		<description><![CDATA[Python had lacked a C equivalent of the &#8220;condition ? true_value : false_value&#8221; expression. So we used a work around until now&#8230; conditional expressions finally made it in to Python&#8217;s 2.5 release.
In Python2.4:
x = ((condition) and true_value) or false_value
In Python2.5:
x = true_value if condition else false_value
Yeah, the statement looks better in Python2.5.
]]></description>
			<content:encoded><![CDATA[<p>Python had lacked a C equivalent of the &#8220;<em>condition ? true_value : false_value</em>&#8221; expression. So we used a work around until now&#8230; conditional expressions finally made it in to Python&#8217;s 2.5 release.</p>
<p>In Python2.4:</p>
<blockquote><p>x = ((condition) and true_value) or false_value</p></blockquote>
<p>In Python2.5:</p>
<blockquote><p>x = true_value if condition else false_value</p></blockquote>
<p>Yeah, the statement looks better in Python2.5.</p>
]]></content:encoded>
			<wfw:commentRss>http://badpopcorn.com/blog/2006/09/19/python-conditional-expressions/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Map, Filter, and Reduce over Python Dictionaries</title>
		<link>http://badpopcorn.com/blog/2006/03/16/map-filter-and-reduce-over-python-dictionaries/</link>
		<comments>http://badpopcorn.com/blog/2006/03/16/map-filter-and-reduce-over-python-dictionaries/#comments</comments>
		<pubDate>Thu, 16 Mar 2006 08:27:15 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://badpopcorn.com/2006/03/16/map-filter-and-reduce-over-python-dictionaries/</guid>
		<description><![CDATA[I wanted to apply some Functional Programming ideas to solve a problem in some Python code I had, which involved manipulation of data found in a couple dictionaries. Unfortunately, the built in map, filter, reduce, and list composition methods can only be used over iterable lists.
Luckily, I remembered that equivalent dictionaries in LISP are all [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to apply some Functional Programming ideas to solve a problem in some Python code I had, which involved manipulation of data found in a couple dictionaries. Unfortunately, the built in map, filter, reduce, and list composition methods can only be used over iterable lists.</p>
<p>Luckily, I remembered that equivalent dictionaries in LISP are all represented as a list-of-lists: ( (key1, val1), (key2, val2) ); python map &#038; filter functions can then be used over this converted datastructure.</p>
<p>After a little digging, I found that it&#8217;s really easy to do this conversion in Python:</p>
<blockquote><p>
# Uses the list composition to make the key value pairs over a dictionary.<br />
dict2list = lambda dic: [(k, v) for (k, v) in dic.iteritems()]</p>
<p># Use the built in dictionary constructor to convert the list.<br />
list2dict = lambda lis: dict(lis)</p>
<p># Example Usage follows:</p>
<p>dict1 = { &#8216;a&#8217;:1, &#8216;b&#8217;:2, &#8216;c&#8217;:3, &#8216;d&#8217;:4 }</p>
<p># Filter function<br />
is_even = lambda item: item[1] % 2 == 0<br />
# Map functions<br />
add_two = lambda item: (item[0], item[1] + 2)<br />
add_sss = lambda item: (&#8220;%s SSS&#8221; % item[0], item[1])<br />
# Reduce function<br />
add_all = lambda x, y: (&#8220;%s %s&#8221; % (x[0], y[0]), x[1] + y[1])</p>
<p># Make sure you have the [] around the reduce call.<br />
list2dict([reduce(add_all, map(add_two, map(add_sss, filter(is_even, dict2list( dict1 )))))])</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://badpopcorn.com/blog/2006/03/16/map-filter-and-reduce-over-python-dictionaries/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Too Many Usernames!</title>
		<link>http://badpopcorn.com/blog/2005/12/07/too-many-usernames/</link>
		<comments>http://badpopcorn.com/blog/2005/12/07/too-many-usernames/#comments</comments>
		<pubDate>Thu, 08 Dec 2005 04:20:20 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://badpopcorn.com/?p=77</guid>
		<description><![CDATA[I am generally tolerant of dumb tech hurdles because I&#8217;m a techie, but I don&#8217;t like having different usernames and passwords for every site I visit&#8211; Yahoo, Google, MSN, etc. Some big companies are trying to solve this problem&#8211; MSN Passport and the Liberty Alliance. But those solutions require huge budgets (and not K.I.S.S), and [...]]]></description>
			<content:encoded><![CDATA[<p>I am generally tolerant of dumb tech hurdles because I&#8217;m a techie, but I don&#8217;t like having different usernames and passwords for every site I visit&#8211; Yahoo, Google, MSN, etc. Some big companies are trying to solve this problem&#8211; MSN Passport and the Liberty Alliance. But those solutions require huge budgets (and not K.I.S.S), and I personally don&#8217;t think that they can realistically solve the problem.</p>
<p>So, if I barely can handle this user account problem, how does a non-techie stand a chance?.</p>
<p>What can be done? For my part, I&#8217;ll be using <a href="http://www.openid.net/">OpenId</a> (Authentication Scheme) and <a href="http://www.yadis.org/">YADIS</a> (Scheme/Service Discovery) in my <a href="http://www.djangoproject.com/">Django</a> projects. Why?</p>
<ul>
<li>They can give my users (and me) a single identity across the web.</li>
<li>They already have good support (LiveJournal, Moveable Type, etc).</li>
<li>They are Simple in design.</li>
<li>They are Open.</li>
<li>They are Federated. Power to the people, not any one mega-corp.</li>
</ul>
<p>To do so, I wrote up a simple pluggable OpenId Authentication Django App that I can use in my projects. The app uses the OpenId Python library put out by the <a href="http://www.openidenabled.com/">OpenId Enabled</a> guys. I shot them email about contributing my code back to their project. This is in progress. If not, I&#8217;ll just release and host it myself.</p>
<p>Next step is to connect my OpenId App, YADIS and Django.</p>
]]></content:encoded>
			<wfw:commentRss>http://badpopcorn.com/blog/2005/12/07/too-many-usernames/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Django and TurboGears, Excitement</title>
		<link>http://badpopcorn.com/blog/2005/12/01/django-and-turbogears-excitement/</link>
		<comments>http://badpopcorn.com/blog/2005/12/01/django-and-turbogears-excitement/#comments</comments>
		<pubDate>Thu, 01 Dec 2005 19:38:04 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://badpopcorn.com/?p=70</guid>
		<description><![CDATA[My last post made the claim that Django hands down beats TurboGears. I know I may have sounded like a &#8220;fanboy&#8221; (I&#8217;m not), but I couldn&#8217;t contain the enthusiasm of what I saw.  
I want to add the following: [edited: Not only do I currently think that Django is better, but also:] I am [...]]]></description>
			<content:encoded><![CDATA[<p>My <a href="http://badpopcorn.com/2005/11/30/django-is-rails/">last post</a> made the claim that <a href="http://www.djangoproject.com/">Django</a> hands down beats <a href="http://www.turbogears.org/">TurboGears</a>. I know I may have sounded like a &#8220;fanboy&#8221; (I&#8217;m not), but I couldn&#8217;t contain the enthusiasm of what I saw. <img src='http://badpopcorn.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I want to add the following: [edited: Not only do I currently think that Django is better, but also:] I am <b>really really excited</b> by the active development found in <b>both</b> projects.</p>
<p>Case in point:</p>
<ul>
<li><a href="http://www.holovaty.com/">Adrian Holovaty</a> commented (Comment section of my last post) that my pet peeves have been or are currently being addressed. Excellent!</li>
<li>Thanks to Cliff Wells for pointing out that <a href="http://checkandshare.com/catwalk/">Catwalk</a> is being added to the next version of TurboGears, correcting my statement about TurboGears lacking an admin interface. I will have to check it out!</li>
<li>Both Projects have active mailing lists and blogging communities.</li>
<li>Coding is active, and new releases are forthcoming.</li>
</ul>
<p>I think this case of &#8220;sibling rivalry&#8221;, if they can be considered siblings, will be helpful in fostering the development of the python-web world. I&#8217;m currently seeing a growth in the perception that this area is really coming into its own with these really cool projects.</p>
<p>And finally, my opinion here isn&#8217;t fixed, so I&#8217;m looking forward to seeing what develops in the future (Let&#8217;s see if Cliff&#8217;s prediction about the TurboGears momentum will come true). I&#8217;ll definitely be making suggestions to both projects when they pop into my mind. And I will submit patches if I run across a bug or a feature idea as I work on my own projects. The future is chock-full of potential on all fronts.</p>
]]></content:encoded>
			<wfw:commentRss>http://badpopcorn.com/blog/2005/12/01/django-and-turbogears-excitement/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Django is Rails</title>
		<link>http://badpopcorn.com/blog/2005/11/30/django-is-rails/</link>
		<comments>http://badpopcorn.com/blog/2005/11/30/django-is-rails/#comments</comments>
		<pubDate>Wed, 30 Nov 2005 18:56:30 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://badpopcorn.com/?p=68</guid>
		<description><![CDATA[The Django Project kicks the living crap out of Turbo Gears for python web application development. I went through the tutorials and documentation from both projects; messed around with writing up some toy applications. I have to say that I&#8217;d choose Django for my work.
What does Django Project have on Turbo Gears?

Django has a more [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.djangoproject.com/">Django Project</a> kicks the living crap out of <a href="http://www.turbogears.org">Turbo Gears</a> for python web application development. I went through the tutorials and documentation from both projects; messed around with writing up some toy applications. I have to say that I&#8217;d choose Django for my work.</p>
<p>What does Django Project have on Turbo Gears?</p>
<ul>
<li>Django has a more cohesive and streamlined feel.</li>
<li>I can use Django on the Dreamhost servers with less hassle. (<a href="http://wiki.dreamhost.com/index.php/Django">Installation instructions</a>)</li>
<li>Django comes with admin interface to manage data in the database.</li>
<li>Django comes with a prebuilt RSS and Atom feed generation application.</li>
<li>Django provides ready to go methods for handling 80% of what you need to do (I&#8217;m talking about Generic Views).</li>
<li>The URL composition and decoupling allows one to make applications really RESTful.</li>
<li>Much of the work only involves wiring up the URLs and the generic views to access the data. No coding.</li>
<li>I&#8217;m writing less code than Turbo Gears, which is almost nothing at all.</li>
</ul>
<p>But I have a few pet peeves about Django:</p>
<ul>
<li>The App&#8217;s url.py file isn&#8217;t truely decoupled from the project. You have to specify a view&#8217;s full package and name, which the project&#8217;s name is part of. But I got around that by declaring a <b>BASE_APPS_PACKAGE</b> settings.py string. Now, I can just copy apps around anywhere.</li>
<li>I&#8217;m not sure if I like putting the URL generation logic in with the model (get_absolute_url). This can tie an app to the project. I added a <b>BASE_URLS</b> settings.py dictionary to map an application to its base url.</li>
<li>The options on generic views don&#8217;t mesh up well. I needed to write up a custom archive_index view, so it wouldn&#8217;t return a 404 when no data is found. I wouldn&#8217;t have needed to if the original view implemented the allow_empty parameter as found on other views.</li>
<li>The generic views only can take custom SQL parameters if they are predefined. I had to extend my custom archive_index view to handle extra parameters taken from a URL path.</li>
</ul>
<p>I&#8217;m finding that I&#8217;m spending less time on the guts of glue work; I&#8217;m focusing on delivering the business solution; I can spend more time on the user interface.</p>
]]></content:encoded>
			<wfw:commentRss>http://badpopcorn.com/blog/2005/11/30/django-is-rails/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>FeedMesh Python Solution</title>
		<link>http://badpopcorn.com/blog/2005/11/11/feedmesh-python-solution/</link>
		<comments>http://badpopcorn.com/blog/2005/11/11/feedmesh-python-solution/#comments</comments>
		<pubDate>Fri, 11 Nov 2005 19:11:47 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://badpopcorn.com/?p=46</guid>
		<description><![CDATA[Ralph Meijer&#8217;s blog has a nice entry about connecting to the FeedMesh network, even with sample code.
This solution was exactly what I was looking for. The Twisted Framework is used for handling both the network connection and the XML streaming (Xish package).
However, I ran into a little problem when testing the code out. I found [...]]]></description>
			<content:encoded><![CDATA[<p>Ralph Meijer&#8217;s blog has a <a href="http://ralphm.net/blog/2005/10/08/twisted_sprint">nice entry</a> about connecting to the FeedMesh network, even with sample code.</p>
<p>This solution was exactly what I was looking for. The <a href="http://www.twistedmatrix.com/">Twisted Framework</a> is used for handling both the network connection and the XML streaming (<a href="http://twistedmatrix.com/projects/xish/">Xish package</a>).</p>
<p>However, I ran into a little problem when testing the code out. I found was that the XmlStreamFactory failed to instantiate. It required another parameter in its constructor. WTF? </p>
<p>Simple reason. Ralph has been making changes to remove all the Jabber specific stuff out of Xish. That parameter was for Jabber and Ralph&#8217;s changes haven&#8217;t made it out into a new release.</p>
<p>So, for those that already have Xish 0.1.0 installed, here are the following code changes:</p>
<pre>auth = xmlstream.Authenticator('')
f = xmlstream.XmlStreamFactory(auth)
</pre>
<p><span id="more-46"></span><br />
Original Sample Code:</p>
<pre>from twisted.xish import xmlstream
from twisted.internet import reactor

def onPing(element):
    print 'Ping for %s' % (element['rss'])

def connected(xs):
    print 'Connected!'
    xs.addObserver('/weblog', onPing)

f = xmlstream.XmlStreamFactory()
f.addBootstrap(xmlstream.STREAM_START_EVENT, connected)

reactor.connectTCP('sandbox.pubsub.com', 9999, f)
reactor.run()
</pre>
<p>[Edited: Changed the code tag to a pre tag (Of the code samples) because those sections weren't rendering nicely.]</p>
]]></content:encoded>
			<wfw:commentRss>http://badpopcorn.com/blog/2005/11/11/feedmesh-python-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
