基础习题(文件操作)

读取一个文件,显示除了以井号(#)开头的行以外的所有行

f = open('test.txt',encoding = "utf-8", mode = 'r')
content = f.readlines()
i = 1
for temp in content:
    if temp[0:1] == "#":
        continue
    else:
        print("%d: %s"%(i,temp) )
        i += 1
f.close()
发布了59 篇原创文章 · 获赞 2 · 访问量 1946

猜你喜欢

转载自blog.csdn.net/weixin_43148062/article/details/104450071