Skip navigation

Category Archives: Python Programming

App Engine StringListProperty and merge join queries offer the ability to perform searches for a variety of purposes.

Read More »

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

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')

I looked at different ways to “Search and Replace” Text in Files Recursively using the Linux Command Line.

Read More »

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 »

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

Read More »

BigTable vs MySql – whats the difference?

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 »

Ministry of Intrigue has a nice python snake Django theme for its Django Blog.

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

Pil or Python Imaging Library is often preferred to PythonMagick – the Python version of Image Magick.