I have a file test.txt which has an array:
array = [3,5,6,7,9,6,4,3,2,1,3,4,5,6,7,8,5,3,3,44,5,6,6,7]
Now what I want to do is get the content of array and perform some calculations with the array. But the problem is when I do open("test.txt") it outputs the content as the string. Actually the array is very big, and if I do a loop it might not be efficient. Is there any way to get the content without splitting , ? Any new ideas?
Does your text file need to look like python syntax? A list of comma separated values would be the usual way to provide data:
Then you could read/write with the
csvmodule or the numpy functions mentioned above. There’s a lot of documentation about how to read csv data in efficiently. Once you had your csv reader data object set up, data could be stored with something like: