def ensure_dirs(filename):
 (dirname, _) = os.path.split(filename)
 if (dirname and (not os.path.exists(dirname))):
  os.makedirs(dirname)

def ensure_dirs ( filename ) : ( dirname , _ ) = os . path . split ( filename ) if ( dirname and ( not os . path . exists ( dirname ) ) ) : os . makedirs ( dirname )
make sure the directories exist for filename .