Other articles


  1. Iterating Through a List and Deleting Elements

    Suppose you're iterating through a list, and you want to remove elements under some condition. This seems pretty easy: you've got an element, and python lists have a remove method that you can call with that element.

    However... let's try it with a simple example:

    >> mylist = range(10)
    >> for x …
    read more
  2. Avoiding Repetitive Methods

    We all know that you should avoid writing the same code over and over: put it in a function and just call that function whenever you need it. But what if what you need is a class with a whole bunch of really similar methods, each with a different name …

    read more
  3. Default Arguments in Python

    In Python, you can assign a default value to an optional varible like so:

    def myFunction(x, y = 0):
        print x + y
    

    myFunction can be called with either one or two arguments. If only one argument is supplied, y will have a value of 0.

    This is all perfectly straightforward …

    read more
  4. Uploading files using Twisted Web

    Inputting information through web forms is really easy under Twisted web. You just have to set up render_GET to display a form, where each input element has a name (e.g. "name", "email", whatever). Then, render_POST, taking an argument of request, can access these values as follows:

    name = request.args …
    read more

social