Python论坛  - 讨论区

标题:[python-chinese] 如何重定向print函数?

2007年03月04日 星期日 12:40

jessinio smith jessinio在gmail.com
星期日 三月 4 12:40:19 HKT 2007

ÏÂÃæµÄ×ö·¨²»ÐÐѽ£¡£º³ö´í£º

IOError: [Errno 9] Bad file descriptor

>import sys
>sys.stdout=open("c:/log.txt",'wb')


> ÎÒÏëÖØ¶¨Ïòprintº¯Êý£¬Ê¹£ºprint "python" Óï¾ä°ÑÄÚÈÝдµ½Ò»¸öÎļþÖУ¡
-- 
×¢ÒâÉíÌ壬ÉíÌåÊǸïÃüµÄ±¾Ç®£¡£¡
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070304/76828f7c/attachment.html 

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

2007年03月04日 星期日 13:02

shhgs shhgs.efhilt在gmail.com
星期日 三月 4 13:02:44 HKT 2007

f = open("c:/log.txt",'wb')
print >>f, "blah, blah, blah"

On 3/3/07, jessinio smith <jessinio在gmail.com> wrote:
> 下面的做法不行呀!:出错:
>
> IOError: [Errno 9] Bad file descriptor
>
>
> >import sys
> >sys.stdout=open("c:/log.txt",'wb')
>
>
> > 我想重定向print函数,使:print "python" 语句把内容写到一个文件中!
> --
> 注意身体,身体是革命的本钱!!
> _______________________________________________
> 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
>

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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号