Python论坛  - 讨论区

标题:[python-chinese] 有没有增强的文件处理模块可以实现插入的操作?

2007年06月29日 星期五 20:46

Can Xue xuecan在gmail.com
星期五 六月 29 20:46:29 HKT 2007

f = open(...)
lines = f.readlines()
lines.insert(line_no, "anything you want")
...

在 07-6-29,pt42<pt4200在gmail.com> 写道:
> 你好:
>
>        有没有增强的文件处理模块可以实现插入的操作?
>
>        比如:文件内容是
> aaa
> bbb
>
>        插入一段字符串ccc后,文件的内容为
> aaa
> ccc
> bbb
>
>         在文件大小为1M以上的情况下,如何实现这个操作?谢谢
> _______________________________________________
> 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]

2007年06月29日 星期五 21:04

橙子 eyeonme在gmail.com
星期五 六月 29 21:04:35 HKT 2007

f = open("file", "r+)
f.seek(3,0)
f.write("bbb")
f.close()

ÔÚ07-6-29£¬Can Xue <xuecan在gmail.com> дµÀ£º
>
> f = open(...)
> lines = f.readlines()
> lines.insert(line_no, "anything you want")
> ...
>
> ÔÚ 07-6-29£¬pt42<pt4200在gmail.com> дµÀ£º
> > ÄãºÃ£º
> >
> >        ÓÐûÓÐÔöÇ¿µÄÎļþ´¦ÀíÄ£¿é¿ÉÒÔʵÏÖ²åÈëµÄ²Ù×÷£¿
> >
> >        ±ÈÈ磺ÎļþÄÚÈÝÊÇ
> > aaa
> > bbb
> >
> >        ²åÈëÒ»¶Î×Ö·û´®cccºó£¬ÎļþµÄÄÚÈÝΪ
> > aaa
> > ccc
> > bbb
> >
> >         ÔÚÎļþ´óСΪ1MÒÔÉϵÄÇé¿öÏ£¬ÈçºÎʵÏÖÕâ¸ö²Ù×÷£¿Ð»Ð»
> > _______________________________________________
> > 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
> >
> _______________________________________________
> 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/20070629/628b36b7/attachment.htm 

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

2007年06月30日 星期六 19:15

pt42 pt4200在gmail.com
星期六 六月 30 19:15:25 HKT 2007

»á¸²¸ÇºóÐøµÄ×Ö·û

Îļþ»á±ä³Éaaabbbcc


ÔÚ07-6-29£¬³È×Ó <eyeonme在gmail.com> дµÀ£º
>
> f = open("file", "r+)
> f.seek(3,0)
> f.write("bbb")
> f.close()
>
> ÔÚ07-6-29£¬Can Xue <xuecan在gmail.com > дµÀ£º
> >
> > f = open(...)
> > lines = f.readlines()
> > lines.insert(line_no, "anything you want")
> > ...
> >
> > ÔÚ 07-6-29£¬pt42<pt4200在gmail.com> дµÀ£º
> > > ÄãºÃ£º
> > >
> > >        ÓÐûÓÐÔöÇ¿µÄÎļþ´¦ÀíÄ£¿é¿ÉÒÔʵÏÖ²åÈëµÄ²Ù×÷£¿
> > >
> > >        ±ÈÈ磺ÎļþÄÚÈÝÊÇ
> > > aaa
> > > bbb
> > >
> > >        ²åÈëÒ»¶Î×Ö·û´®cccºó£¬ÎļþµÄÄÚÈÝΪ
> > > aaa
> > > ccc
> > > bbb
> > >
> > >         ÔÚÎļþ´óСΪ1MÒÔÉϵÄÇé¿öÏ£¬ÈçºÎʵÏÖÕâ¸ö²Ù×÷£¿Ð»Ð»
> > > _______________________________________________
> > > 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
> > >
> > _______________________________________________
> > 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
>
>
>
> _______________________________________________
> 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/20070630/0abb66d7/attachment.html 

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

2007年06月30日 星期六 19:16

pt42 pt4200在gmail.com
星期六 六月 30 19:16:49 HKT 2007

ÕâÖÖ·½·¨Ò²Êǽ«Îļþ¶ÁÈëÄÚ´æºó£¬ÔÙдÈëÎļþ

ЧÂʲ»¸ß


ÔÚ07-6-29£¬Can Xue <xuecan在gmail.com> дµÀ£º
>
> f = open(...)
> lines = f.readlines()
> lines.insert(line_no, "anything you want")
> ...
>
> ÔÚ 07-6-29£¬pt42<pt4200在gmail.com> дµÀ£º
> > ÄãºÃ£º
> >
> >        ÓÐûÓÐÔöÇ¿µÄÎļþ´¦ÀíÄ£¿é¿ÉÒÔʵÏÖ²åÈëµÄ²Ù×÷£¿
> >
> >        ±ÈÈ磺ÎļþÄÚÈÝÊÇ
> > aaa
> > bbb
> >
> >        ²åÈëÒ»¶Î×Ö·û´®cccºó£¬ÎļþµÄÄÚÈÝΪ
> > aaa
> > ccc
> > bbb
> >
> >         ÔÚÎļþ´óСΪ1MÒÔÉϵÄÇé¿öÏ£¬ÈçºÎʵÏÖÕâ¸ö²Ù×÷£¿Ð»Ð»
> > _______________________________________________
> > 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
> >
> _______________________________________________
> 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/20070630/a6b46efe/attachment.html 

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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号