Skip to content

Instantly share code, notes, and snippets.

@spranesh
spranesh / dispatch.py
Created May 21, 2011 09:43
Dynamic Dispatch in Python
def Analyse(obj):
""" Dynamic Dispatch based on object's class type.
This will call the AnalyseClassName
Example: if obj is of type Let, then call AnalyseLet,
if it is of type IfElse call AnalyseIfElse
"""
# Get obj's class name
class_name = obj.__class__.__name__
# Create the function name as a string
@spranesh
spranesh / directed_graph.py
Created May 17, 2011 08:17
Directed Graph class
""" Implementation of a simple directed graph with no weights.
Test by either running python on this file,
or by calling nosetests on this file.
"""
import unittest
import collections
class DirectedGraph:
@spranesh
spranesh / plot.py
Created March 9, 2011 14:19
Plot data using matplotlib
#!/usr/bin/env python
""" A script to plot data using matplotlib.
Usage: [prog] [options] file1 file2 ..
The files passed are assumed to contain two values (x, y) per line.
There are two ways of using this script -- from the shell, or by calling the
Plot function with the appropriate arguments.