Python论坛  - 讨论区

标题:[python-chinese] 怎么判断文件是否存在?

2006年04月24日 星期一 18:56

huang yipeng yipenghuang at gmail.com
Mon Apr 24 18:56:18 HKT 2006

请问大家:
     怎么判断文件是否存在?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060424/75ac6bd6/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年04月24日 星期一 20:01

Shixin Zeng zeng.shixin at gmail.com
Mon Apr 24 20:01:27 HKT 2006

On 4/24/06, huang yipeng <yipenghuang at gmail.com> wrote:
>
> 请问大家:
>      怎么判断文件是否存在?
>

import os
os.path.exists("the_path_to_the_file")

_______________________________________________
> 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
>
>


--
Best Regards

Shixin Zeng
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060424/5f140530/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年04月24日 星期一 20:09

Shixin Zeng zeng.shixin at gmail.com
Mon Apr 24 20:09:13 HKT 2006

On 4/24/06, Shixin Zeng <zeng.shixin at gmail.com> wrote:
>
>
>
> On 4/24/06, huang yipeng <yipenghuang at gmail.com> wrote:
> >
> > 请问大家:
> >      怎么判断文件是否存在?
> >
>
> import os
> os.path.exists("the_path_to_the_file")
>

或者:
os.access("the_path_to_the_file", os.F_OK)
再或者:
try:
         os.stat("the_path_to_the_file")
except:
         print "doesn't exist"
else:
          print "exist"



_______________________________________________
> > 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
> >
> >
>
>
> --
> Best Regards
>
> Shixin Zeng
>



--
Best Regards

Shixin Zeng
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060424/dff66aa0/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年04月25日 星期二 09:19

Qutr qutianrang at gmail.com
Tue Apr 25 09:19:04 HKT 2006

好好看看os模块,里面有文件操作的各种方法。

Qutr,qutianrang at gmail.com
2006-4-25 
----- Original Message ----- 
From: huang yipeng 
To: python-chinese 
Sent: 2006-04-24, 18:56:18
Subject: [python-chinese] 怎么判断文件是否存在?


请问大家:
     怎么判断文件是否存在?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060425/9f196794/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号