Tuesday, April 22, 2008

Adding lots of Python __init__.py files

Lots of subpackages?

import os

names = os.listdir('.')
for name in names:
try:
os.popen('touch %s/__init__.py' % name)
except:
pass

Adds an __init__.py file to every subdirectory.

1 comment:

Jared Grubb said...

Why 'os.popen' rather than 'open'? What am I missing?