See also: Heapify

Pages: 1

Prototyping in Python

Our good friend Randall was talking about how he liked prototype inheritance such as that in JavaScript. He enjoyed how you can add, modify and remove methods from JavaScript classes and have them apply to all object instances.

Amazed as he was, he's now forcing me at gun point to write a post about it!

The first thing you have to understand about Python classes is that all they are is a collection of references to members. Methods are just function pointers that are referenced by the class, not embedded or copied into the class. This is why all methods require that the first parameter be self, the current instance. Instances themselves contain the real state and reference the class. When you invoke a method on the instance it looks up what function to call.

...

Read more

There are no comments on this post.

Ignoring certain content-types with urllib (Python Snippet)

This is a little piece of code I wrote to intercept and disregard a http or https request from urllib.urlopen if the Content-Type header on the response is not within a list of accepted content types.

I'm sure somebody might find a use for this.

This snippet creates a customer URLopener and then overrides the open_http and open_https methods, checks for MIME type and halts the request if the response is of a MIME type you do not accept.

...

Read more

There are no comments on this post.

Pages: 1

RSS
Powered by Debian, Guinness, and excessive quantities of caffeine and sugar.