Finding empty directories in Python

Date Tags Python

Late one night I needed to write some Python code to recursively find empty directories. Searching online produced some unsatisfactory solutions. Here is a simple solution that leverages os.walk.

import os

empty_dirs = []
for root, dirs, files in os.walk(starting_path):
   if not len(dirs) and not len(files):
       empty_dirs ...

View comments.

more ...


A C & Python chained assignment gotcha

Date Tags Python / C++

Late last night I had a marathon debugging session where I discovered I had been burned by not fully understanding chaining assignment statements in Python. I was porting some C code to Python that had some chained assignment expressions. C and C++ programmers are well used to this idiom which ...

View comments.

more ...


Introducing weighmail

Recently my wife approached me and told me that Gmail was warning her that she was using 95% of her (free) quota. This was a bit surprising, but my wife does a lot of photography, and sends lots of photos through the mail to various people. So I began helping ...

View comments.

more ...