2006年04月08日 星期六 01:53
*os.path.exists() 和 os.path.isdir() 有什么区别?*
我在看 limodou 的 crawl 代码,遇到这个疑点,看帮助,自己试验都没能弄清楚,所以问一下。
这段代码这样写的:
if not isdir(dir): # create archive dir if nec.
if exists(dir): unlink(dir)
try:
makedirs(dir)
except:
pass
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060408/cb0ba074/attachment.html
2006年04月08日 星期六 08:04
if not isdir(dir): #如果dir不是目录
if exists(dir): unlink(dir) #dir不是目录,如果存在dir,那么dir是个文件么,就删除这个文件
try:
makedirs(dir) #创建dir这个目录
except:
pass
在06-4-8,Neil <chenrong2003 at gmail.com> 写道:
>
> *os.path.exists() 和 os.path.isdir() 有什么区别?*
>
> 我在看 limodou 的 crawl 代码,遇到这个疑点,看帮助,自己试验都没能弄清楚,所以问一下。
> 这段代码这样写的:
>
> if not isdir(dir): # create archive dir if nec.
> if exists(dir): unlink(dir)
> try:
> makedirs(dir)
> except:
> pass
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
--
I like Python & Linux.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060408/a2962c61/attachment.html
2006年04月08日 星期六 16:07
了解了。谢谢! 原来 exists 可以同时判断文件或者目录是否存在。 因为我是一直用 C# 的,在那里是区分为 File.Exists() 和 Directory.Exists() 两个不同的方法。没想到这点,呵呵。 2006/4/8, 员旭鹏 <recordus at gmail.com>: > > if not isdir(dir): #如果dir不是目录 > if exists(dir): unlink(dir) > #dir不是目录,如果存在dir,那么dir是个文件么,就删除这个文件 > try: > makedirs(dir) #创建dir这个目录 > except: > pass > > 在06-4-8,Neil <chenrong2003 at gmail.com> 写道: > > > > *os.path.exists() 和 os.path.isdir() 有什么区别?* > > > > 我在看 limodou 的 crawl 代码,遇到这个疑点,看帮助,自己试验都没能弄清楚,所以问一下。 > > 这段代码这样写的: > > > > if not isdir(dir): # create archive dir if nec. > > if exists(dir): unlink(dir) > > try: > > makedirs(dir) > > except: > > pass > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese at lists.python.cn > > Subscribe: send subscribe to python-chinese-request at lists.python.cn > > Unsubscribe: send unsubscribe to > > python-chinese-request at lists.python.cn > > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > > > > > > -- > I like Python & Linux. > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060408/ad02a4f5/attachment.htm
Zeuux © 2025
京ICP备05028076号