比系统自带的更加友好的makedir函数,自带makedir函数,Python语言: Py
文章由Byrx.net分享于2019-03-23 08:03:16
比系统自带的更加友好的makedir函数,自带makedir函数,Python语言: Py
Python语言: Python Cookbook: 比系统自带的更加友好的makedir函数#from: <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82465">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)#该片段来自于http://byrx.net
相关内容
- Python 读取mp3 ID3信息,python读取mp3id3,from mutagen
- 批量转换Linux文件权限,批量转换linux权限,使用窗口管
- python使用自定义的user-agent抓取网页,pythonuser-agent,imp
- python根据ip地址反向查找主机名称,pythonip查找主机,i
- python获取当前时间的前一天,前一周,前一个月。,
- 只需按一下,py2exe打包生成器,py2exe打包,易中天在先秦
- 读取系统环境变量,读取环境变量,import osfil
- 在python的类和函数中使用静态变量,python静态,方法一
- python qrcode库生成二维码,pythonqrcode库,简单用法import
- python中的黄金分割法,python黄金分割法,''' a,b = br
评论关闭