This post lists some common operations in Python such as file operation and time handling.

File Operations

try:
    with open('infile','r') as infile, open('outfile','r') as outfile:
        for line in infile:
            # handle each line in the file
            outfile.write(line.strip() + '\n')
except IOError:
    # do something
    

Time Handling

datetime in Python2.x or Python 3.x.

Note that the format codes listed in strftime are slightly different from what is mentioned here