Fix Python – Making a python user-defined class sortable, hashable

What methods need to be overridden/implemented when making user-defined classes sortable and/or hashable in python?
What are the gotchas to watch out for?
I type dir({}) into my interpreter to get a list of methods on built-in dicts. Of those, I assume I need to some implement some subset of
[‘__cmp__’, ‘__eq__’, ‘__ge__’, ‘__gt__’, ‘__hash__’, ‘….

Fix Python – How to extend a class in python?

In python how can you extend a class? For example if I have
class Color:
def __init__(self, color):
self.color = color
def getcolor(self):
return self.color
import Color

class Color:
def getcolor(self):
return self.color + ” extended!”

But this doesn’t work…
I expect that if I wor….

Fix Python – How do I get the filepath for a class in Python?

Given a class C in Python, how can I determine which file the class was defined in? I need something that can work from either the class C, or from an instance off C.
The reason I am doing this, is because I am generally a fan off putting files that belong together in the same folder. I want to create a class that uses a Django template to render ….

Fix Python – Should I use a class or dictionary?

I have a class that contains only fields and no methods, like this:
class Request(object):

def __init__(self, environ):
self.environ = environ
self.request_method = environ.get(‘REQUEST_METHOD’, None)
self.url_scheme = environ.get(‘wsgi.url_scheme’, None)
self.request_uri = wsgiref.util.request_uri(environ)