def makedirs_count(path, count=0):
 (head, tail) = os.path.split(path)
 if (not tail):
  (head, tail) = os.path.split(head)
 if (head and tail and (not os.path.exists(head))):
  count = makedirs_count(head, count)
  if (tail == os.path.curdir):
   return
 try:
  os.mkdir(path)
 except OSError as e:
  if ((e.errno != errno.EEXIST) or (not os.path.isdir(path))):
   raise
 else:
  count += 1
 return count

def makedirs_count ( path , count = 0 ) : ( head , tail ) = os . path . split ( path ) if ( not tail ) : ( head , tail ) = os . path . split ( head ) if ( head and tail and ( not os . path . exists ( head ) ) ) : count = makedirs_count ( head , count ) if ( tail == os . path . curdir ) : return try : os . mkdir ( path ) except OSError as e : if ( ( e . errno != errno . EEXIST ) or ( not os . path . isdir ( path ) ) ) : raise else : count += 1 return count
same as os .