alibabamama 发表于 2018-8-11 12:27:20

python读文件

  文件 1 内容如下
  #some words
  Sometimes in life,
  You find a special friend;
  Someone who changes your life just by being part of it.
  Someone who makes you laugh until you can't stop;
  Someone who makes you believe that there really is good in the world.
  Someone who convinces you that there really is an unlocked door just waiting
  for you to open it.
  This is Forever Friendship.
  使用读文件过滤空行和注释行
  import re
  file=open("1",'r')
  a=file.readlines()
  a.sort()
  forline ina:
  ifre.match("^#",line):
  pass
  elifre.match("^$",line):
  pass
  else:
  print line.strip()
页: [1]
查看完整版本: python读文件