Read only the first line of a file?

前端 未结 8 1060
死守一世寂寞
死守一世寂寞 2021-01-29 21:29

How would you get only the first line of a file as a string with Python?

相关标签:
8条回答
  • 2021-01-29 22:30
    first_line = next(open(filename))
    
    0 讨论(0)
  • 2021-01-29 22:32
    infile = open('filename.txt', 'r')
    firstLine = infile.readline()
    
    0 讨论(0)
提交回复
热议问题