Create a List that contain each Line of a File

前端 未结 8 1507
无人及你
无人及你 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:29

    Assuming you also want to strip whitespace at beginning and end of each line, you can map the string strip function to the list returned by readlines:

    map(str.strip, open('filename').readlines())
    

提交回复
热议问题