python读取文本

orArvin 2011-04-29 10:59:49

# -*- coding: cp936 -*-
count = 0
sa = 0
stra = '';
def func():
global count
global sa;
global stra;

if count == 6:
sa = sa+1;
#print 'sa' + str(sa) + 'count' + str(count);
count = 0;
stra = '\n'
else:
stra = ''


fh = open('F:\\wwb\\python\\other.txt');
fw = open('F:\\wwb\\python\\other_new.txt','a+');
for lh in fh.readlines():
#print "==" + stra + "==" + stra + "==" + lh

ss = lh.split(':');
if(lh.startswith('F_XM:')):
count = count + 1
func();
#left, sep, right = lh.partition('F_XM:');
fw.writelines('姓名 : ' + ss[1] + stra);
continue;
if(lh.startswith('F_DZYJ:')):
count = count + 1
func();
#left, sep, right = lh.partition('F_DZYJ:');
fw.writelines('邮箱 : ' + ss[1] + stra);
continue;
if(lh.startswith('F_FJ:')):
count = count + 1
func();
#left, sep, right = lh.partition('F_FJ:');
fw.writelines('分机 : ' + ss[1] + stra);
continue;
if(lh.startswith('F_SJ:')):
count = count + 1
func();
#left, sep, right = lh.partition('F_SJ:');
fw.writelines('手机 : ' + ss[1] + stra);
continue;
if(lh.startswith('F_GH:')):
count = count + 1
func();
#left, sep, right = lh.partition('F_GH:');
fw.writelines('工号 : ' + ss[1] + stra);
continue;
if(lh.startswith('F_XMPY:')):
count = count + 1
func();
#left, sep, right = lh.partition('F_XMPY:');
fw.writelines('拼音 : ' + ss[1] + stra);
continue;

fh.close();
fw.close();
...全文
120 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ruby65kg 2012-09-17
  • 打赏
  • 举报
回复
喜欢PYTHON的简洁,我也有自翻译相关文章,请多多指导:http://www.yiibai.com/python
相互学习,共同进步。

590

社区成员

发帖
与我相关
我的任务
社区描述
提出问题
其他 技术论坛(原bbs)
社区管理员
  • community_281
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧