比系统自带的更加友好的makedir函数,自带makedir函数,[Python]代码Py
比系统自带的更加友好的makedir函数,自带makedir函数,[Python]代码Py
[Python]代码
Python语言: Python Cookbook: 比系统自带的更加友好的makedir函数#from: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82465def _mkdir(newdir): """works the way a good mkdir should :) - already exists, silently complete - regular file in the way, raise an exception - parent directory(ies) does not exist, make them as well """ if os.path.isdir(newdir): pass elif os.path.isfile(newdir): raise OSError("a file with the same name as the desired " \ "dir, '%s', already exists." % newdir) else: head, tail = os.path.split(newdir) if head and not os.path.isdir(head): _mkdir(head) #print "_mkdir %s" % repr(newdir) if tail: os.mkdir(newdir)
相关内容
- 打印杨辉三角形,杨辉三角形,[Python]代码Py
- 求最大最小最大值因数,最大值因数,[Python]代码Py
- 筛法生成质数(素数)的生成器,质数素数,[Python]代码
- 用类快排的方法找寻"第n小"的数,
- 计算n*n网格生成树的数目,网格,[Python]代码Py
- python实现统计word的小程序,pythonword小程序,[Python]代码
- HTML颜色和RGB颜色互转,html颜色rgb,[Python]代码Py
- 常见的Python字符串操作和一下小技巧,python字符串,[P
- python中获取按键(跨平台),python获取按键,[Python]代码P
- Python将内容中的Url地址转换成Tinyurl地址,pythontinyurl,
评论关闭