Chinaunix首页 | 论坛 | 博客
  • 博客访问: 612109
  • 博文数量: 69
  • 博客积分: 1891
  • 博客等级: 上尉
  • 技术积分: 1359
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-20 23:38
文章分类

全部博文(69)

文章存档

2012年(46)

2011年(23)

分类: Python/Ruby

2011-07-04 22:42:09

读取文件cdays−4-test.txt 内容,去除空行和注释行后,以行为单位进行排序,并将
结果输出为cdays−4-result.txt。

  1. infile = file('mycd.cdc2','r')
  2. outfile = file('mycd.cdc2.out','w')

  3. str = infile.readline()

  4. while str:
  5.     if (not str.startswith('#')) and str!="\n":
  6.        outfile.write(str)
  7.     str = infile.readline()

  8. infile.close()
  9. outfile.close()
语法点:
python没有null,判断非空用not
python读入的空行为"\n"
阅读(1114) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~