“tail -f”-like generator

后端 未结 2 1619
伪装坚强ぢ
伪装坚强ぢ 2021-01-11 19:42

I had this convenient function in Python:

def follow(path):
    with open(self.path) as lines:
        lines.seek(0, 2)  # seek to EOF

        while True:
          


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-11 20:19

    Check out this Go package for reading from continuously updated files (tail -f): https://github.com/hpcloud/tail

    t, err := tail.TailFile("filename", tail.Config{Follow: true})
    for line := range t.Lines {
        fmt.Println(line.Text)
    }
    

提交回复
热议问题