I don’t know Python but I did see a couple of referrers yesterday that offered the Python version of my little example. Here it is:

if depth: depth = depth + datadir.count('/') - 1

Now I know why Python programmers seem so smug.