I have been practising reading files in Python, as I am new to that particular area.
I have a text file like:
Hello,my,name,is,Jack
and I want to transfer that to a list
like this:
["Hello", "my", "name", "is", "Jack"]
I tried doing this:
array = []
file = open("Names.txt", "r")
for line in file:
array.append(line.split(","))
print(array)
but I got a really bizarre error
:
File "C:\Python27\lib\random.py", line 261, in choice
return seq[int(self.random() * len(seq))] # raises IndexError if seq is
empty
IndexError: list index out of range
>>>
How do I fix it?