Skip navigation

Tag Archives: python

Finally, a simple explanation of @staticmethod vs @classmethod.

Read More »

Drupal 6 uses different methods for saving taxonomy for different taxonomy types.

For multiple select based taxonomy:


$nodeObj->taxonomy = array(2=>array(15,19));


nodeOb['taxonomy']['2'] = [15,19]

For tags based taxonomy:


$nodeObj->taxonomy = array(
  'tags' => array(

Assuming you’ve downloaded ./configure && make && make install the latest nginx and have mysql, svn already installed. More info on installing svn and setting up svn here.

Read More »

import email, getpass, imaplib, os

detach_dir = '.'

### directory where to save attachments (default: current)

m = imaplib.IMAP4_SSL('', 993)
keywordsSearch = 'bananas oranges'
searchString = "(ALL SUBJECT '%s')" % keywordsSearch

###, "(ALL SUBJECT 'bananas oranges')")
resp, items =, searchString)
items = items[0].split()
for emailid in items:
    resp, data = m.fetch(emailid, "(RFC822)")
    email_body = data[0][1]
    mail = email.message_from_string(email_body)
    if mail.get_content_maintype() != 'multipart':
    print "["+mail["From"]+"] :" + mail["Subject"]
    for part in mail.walk():
        if part.get_content_maintype() == 'multipart':
        if part.get('Content-Disposition') is None:
        filename = part.get_filename()
        counter = 1
        if not filename:
            filename = 'part-%03d%s' % (counter, 'bin')
            counter += 1
        att_path = os.path.join(detach_dir, filename)
        if not os.path.isfile(att_path) :
            fp = open(att_path, 'wb')

Multi form “http post” with python.

Read More »

If you want to set a limit when you iterate a list in python slice it up by doing this:

for i in list[0:6]:
print i

This will list the first 5 items.

You can’t use ‘tidy’ python binding with App Engine as far as I know so use this for cleaning up your xml and html characters:

import cgi
string = str('I hate monkey & hyena characters')

Should print out:

I hate monkey & hyena characters

If you want to change the content type or mime type for your Google App Engine template:

self.response.headers['Content-Type'] = "application/xml"

Full example:

class MainPage(webapp.RequestHandler):
def get(self):
greetings_query = databasemodel.all()

template_values = {
'greetings': greetings_query
self.response.headers['Content-Type'] = "application/xml"
path = os.path.join(os.path.dirname(__file__), 'templates/index.xml')
self.response.out.write(template.render(path, template_values))

Here’s a quick set up for Google App Engine’s SDK on Nginx.

Read More »

One easy way to compare lists in python is to use Python Sets.

Read More »

If you get the error:

mysqlimport: Error: Table ‘database.mydatabase’ doesn’t exist

Read More »

Proper syntax for svn import on Ubuntu. Read More »

Parsing feeds in Python is best achieved with Mark Pilgrims Universal Feed Parser.

Read More »

Komodo Edit is one of my favorite editors. In this quick run down you can find out:

  • How to organise App Engine projects on Komodo Edit
  • Python Code Intelligence Auto-Complete
  • Launch the development server

Read More »

Another Django Helper for Google App Engine. Read the article here.

Read More »

Use your Google Account as your OpenID account with App Engine.

Read More »

Here is a tutorial which explains how to build faster PyFacebook Facebook Apps. Will uses Django.

Read More »

Here’s a tutorial which shows you how to build your own search engine with the Yahoo Search API and Google App Engine.

Read More »

Are you not so sure about Google App Engine’s BigTable ER – Entity Relationship Database Model?

Here’s a simple tutorial which shows you how to create databases the ER way plus a little bit of GQL.

Read More »

A new aggregator of Google App Engine blog posts is up and running here.

Read More »

This is the best post I’ve seen on App Engine so far.

Read More »

Update: Seems PIL does not work on App Engine yet so you may want to grab the gdata python client and use picasa to host and manipulate your photos. Otherwise we’ll have to wait until Google includes it or someone tightens up PIL so its all native Python.

How to manipulate images in Python on Google App Engine?

Read More »

Steven Osborn wrote this Django for Google App Engine. Read More »

Regular expression tutorials for Python and Grep.

Tutorial One

Tutorial Two