Users Pricing

forum

Home Forums Create a List that contain each Line of a File in Python – MindStick

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

Erick Wilsom 1086 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?


2 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md