Create a List that contain each Line of a File

前端 未结 8 1469
无人及你
无人及你 2020-12-23 16:52

I\'m trying to open a file and create a list with each line read from the file.

   i=0
   List=[\"\"]
   for Line in inFile:
      List[i]=Line.split(\",\")
         


        
相关标签:
8条回答
  • 2020-12-23 17:31

    It's a lot easier than that:

    List = open("filename.txt").readlines()
    

    This returns a list of each line in the file.

    0 讨论(0)
  • 2020-12-23 17:31
    my_list = [line.split(',') for line in open("filename.txt")]
    
    0 讨论(0)
提交回复
热议问题