how to output every line in a file python

后端 未结 5 2143
执笔经年
执笔经年 2021-01-04 04:01
     if data.find(\'!masters\') != -1:
         f = open(\'masters.txt\')
         lines = f.readline()
         for line in lines:
               print lines
               


        
5条回答
  •  青春惊慌失措
    2021-01-04 04:53

    Did you try

    for line in open("masters", "r").readlines(): print line
    

    ?

    readline() 
    

    only reads "a line", on the other hand

    readlines()
    

    reads whole lines and gives you a list of all lines.

提交回复
热议问题