python, unique files by content

I would like to retrieve a list of unique files by content rather than by filename. That is, if spam.txt and eggs.txt both contained the same contents I want only one of them to return. A very simple approach is to compute a SHA-1 checksum on each file, and build a dictionary with the checksum […]

python daemon

I would like to create a python daemon, completely detaching from the terminal or parent process, and yet retaining any log handlers through the python logging module. There is a wonderful example at cookbook-278731 of a well-behaved daemon, and see PEP 3143. Borrowing from these examples, here is a simple daemonize function that will retain […]

python logging

I would like customizable logging in python applications, and I would like to easily send log messages to multiple handlers without any modification of the application code. The built-in logging module provides a very robust and easy-to-use logging capability. In it’s simplest form, log messages will be sent to the console with minimal formatting, e.g., […]

python Fibonacci list

The Fibonacci sequence in python looks something like this def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-1) + fib(n-2) But expect stack overflows for even small values of n, e.g., fib(60) will require over 3 trillion function calls. You can use the Fibonacci sequence itself to […]

scraping and parsing html

I would like to read J. Krishnamurti books on my Kindle. Unfortunately, no ebooks were available although I did find that jkrishnamurti.org has an extensive collection of books on their website. At present there is no full download, only a per-chapter html viewer, and some of the books ran over 80 chapters, which is more […]