forum

Home / DeveloperSection / Forums / Create a List that contain each Line of a File in Python

Create a List that contain each Line of a File in Python

Erick Wilsom 232 27-Oct-2022

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

   i=0

   list=[""]
   for data in file_name:
      list[i]=data.split(",")
      i+=1
   print list

But this sample code gives me an error because of the i+=1 saying that index is out of range. What's my problem here? How can I write the code in order to increment my list with every new Line in the InFile?


Updated on 19-Jun-2023
Writing is my profession! I have written hundreds of article for many organizations and looking forward to work with growing organization. I am compatible to produce content in many categories including International politics, Healthcare, Education, Lifestyle, etc.. I understand the value of your time that you have invested to read my bio. #thanks

Can you answer this question?


Answer

2 Answers

Liked By