您可以尝试以下方法:
# top of the fileimport osimport errno# the actual pretry: os.makedirs(directory_name)except OSError as exc: if exc.errno == errno.EEXIST and os.path.isdir(directory_name): pass

您可以尝试以下方法:
# top of the fileimport osimport errno# the actual pretry: os.makedirs(directory_name)except OSError as exc: if exc.errno == errno.EEXIST and os.path.isdir(directory_name): pass