读取文件cdays−4-test.txt 内容,去除空行和注释行后,以行为单位进行排序,并将
结果输出为cdays−4-result.txt。
- infile = file('mycd.cdc2','r')
-
outfile = file('mycd.cdc2.out','w')
-
-
str = infile.readline()
-
-
while str:
-
if (not str.startswith('#')) and str!="\n":
-
outfile.write(str)
-
str = infile.readline()
-
-
infile.close()
-
outfile.close()
语法点:
python没有null,判断非空用not
python读入的空行为"\n"
阅读(1155) | 评论(0) | 转发(0) |