how to form a list from a file in python code example

Example 1: how to form a list from a file in python

l = []
for line in in_file:
    l.append(line.rstrip().split(','))

Example 2: how to form a list from a file in python

my_list = [line.split(',') for line in open("filename.txt")]

Example 3: how to form a list from a file in python

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

Example 4: how to form a list from a file in python

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

Example 5: how to form a list from a file in python

for line in a_file:

Example 6: how to form a list from a file in python

list_of_lists = []

Example 7: how to form a list from a file in python

a_file = open("sample.txt", "r")

Example 8: how to form a list from a file in python

myFile= open( "SomeFile.txt", "r" )
for x in myFile:
    print x
myFile.close()

Example 9: how to form a list from a file in python

l = []
for line in in_file:
    l.append(line.split(','))