代码之家  ›  专栏  ›  技术社区  ›  helpermethod

为什么我不能对打开的文件调用read()两次?

  •  80
  • helpermethod  · 技术社区  · 16 年前

    read()

    这是密码

    f = f.open()
    
    # get the year
    match = re.search(r'Popularity in (\d+)', f.read())
    
    if match:
      print match.group(1)
    
    # get all the names
    matches = re.findall(r'<td>(\d+)</td><td>(\w+)</td><td>(\w+)</td>', f.read())
    
    if matches:
      # matches is always None
    

    当然我知道这不是最有效或最好的方法,这不是重点。关键是,为什么我不能打电话

    7 回复  |  直到 10 年前
    推荐文章