Python论坛  - 讨论区

标题:[python-chinese] 如果向一个不存在的目录里面写入数据文件

2007年11月29日 星期四 14:47

篱笆 nameliba在gmail.com
星期四 十一月 29 14:47:00 HKT 2007

rt
Ö»ÄÜÏȽ¨Ä¿Â¼²ÅÄÜдÈëÉú³ÉÎļþÂð?
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20071129/575c3bc1/attachment.htm 

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

2007年11月29日 星期四 14:51

Leo Jay python.leojay在gmail.com
星期四 十一月 29 14:51:44 HKT 2007

On Nov 29, 2007 2:47 PM, 篱笆 <nameliba在gmail.com> wrote:
> rt
> 只能先建目录才能写入生成文件吗?

是的。


-- 
Best Regards,
Leo Jay

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

2007年11月29日 星期四 17:32

jessinio liang jessinio在gmail.com
星期四 十一月 29 17:32:36 HKT 2007

使用open函数的a参数:在有文件时会追加,没有文件时创建后追加

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

2007年11月30日 星期五 09:07

昆仑 jackyboy在163.com
星期五 十一月 30 09:07:32 HKT 2007

Ó¦¸ÃµÄÈ·Èç´ËµÄ£¬ÔÚwin32µÄAPIÀÓÐÒ»¸öMakeSureDirectoryExistsµÄº¯Êý£¬¿ÉÒÔ½«²ÎÊýÀïµÄĿ¼¶¼¸ø´´½¨³öÀ´£¬²»ÖªµÀpythonµÄ¿âÀïÓÐûÓС£
²»¹ý¾ÍËãûÓÐ×Ô¼ºÐ´Ò»¸öº¯ÊýÒ²²¢²»Â鷳Ĩ¡£


2007-11-30 



À¥ÂØ 



·¢¼þÈË£º Àé°Ê 
·¢ËÍʱ¼ä£º 2007-11-29  14:48:08 
ÊÕ¼þÈË£º pythonÓʼþÁбí 
³­ËÍ£º 
Ö÷Ì⣺ [python-chinese] Èç¹ûÏòÒ»¸ö²»´æÔÚµÄĿ¼ÀïÃæÐ´ÈëÊý¾ÝÎļþ 
 
rt
Ö»ÄÜÏȽ¨Ä¿Â¼²ÅÄÜдÈëÉú³ÉÎļþÂð?
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20071130/b31d707f/attachment.html 

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

2007年11月30日 星期五 09:12

篱笆 nameliba在gmail.com
星期五 十一月 30 09:12:32 HKT 2007

Òѽâ¾ö

ÔÚ07-11-30£¬À¥ÂØ <jackyboy在163.com> дµÀ£º
>
>
> Ó¦¸ÃµÄÈ·Èç´ËµÄ£¬ÔÚwin32µÄAPIÀÓÐÒ»¸öMakeSureDirectoryExistsµÄº¯Êý£¬¿ÉÒÔ½«²ÎÊýÀïµÄĿ¼¶¼¸ø´´½¨³öÀ´£¬²»ÖªµÀpythonµÄ¿âÀïÓÐûÓС£
> ²»¹ý¾ÍËãûÓÐ×Ô¼ºÐ´Ò»¸öº¯ÊýÒ²²¢²»Â鷳Ĩ¡£
>
>
> 2007-11-30
> ------------------------------
>  À¥ÂØ
> ------------------------------
>  *·¢¼þÈË£º* Àé°Ê
> *·¢ËÍʱ¼ä£º* 2007-11-29  14:48:08
> *ÊÕ¼þÈË£º* pythonÓʼþÁбí
> *³­ËÍ£º*
> *Ö÷Ì⣺* [python-chinese] Èç¹ûÏòÒ»¸ö²»´æÔÚµÄĿ¼ÀïÃæÐ´ÈëÊý¾ÝÎļþ
>  rt
> Ö»ÄÜÏȽ¨Ä¿Â¼²ÅÄÜдÈëÉú³ÉÎļþÂð?
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20071130/552d8202/attachment.html 

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

2007年11月30日 星期五 09:12

limodou limodou在gmail.com
星期五 十一月 30 09:12:49 HKT 2007

On Nov 30, 2007 9:07 AM, 昆仑 <jackyboy在163.com> wrote:
>
>
> 应该的确如此的,在win32的API里,有一个MakeSureDirectoryExists的函数,可以将参数里的目录都给创建出来,不知道python的库里有没有。
> 不过就算没有自己写一个函数也并不麻烦呢。
>
os.makedirs可以一次创建多个目录,但是如果目录已经存在,则报错,可以先检查是否存在,再创建,如:

import os

if not os.path.exists(dirs):
    os.makedirs(dirs)

-- 
I like python!
UliPad <>: http://code.google.com/p/ulipad/
meide <>: http://code.google.com/p/meide/
My Blog: http://www.donews.net/limodou

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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号