Python - How to get text file data into an array on python.
Ok, so I've already used line split stuff to transform my data into something like this in a text file:
Code:
['1', '1', '3', '20.7505207'] Thanks. |
Here's /a/ way.
(1) First, get rid of the array business. Code:
cat foo.txt | sed "s/[',[]]*//g" > bar.txt Code:
1 1 3 20.7505207 Code:
#!/usr/bin/python |
you can try eval. But seriously, you should consider the pickle module if you want to store data structures in a file and reload it back.
|
Oh wow! I never thanked you two. I've used this information several times now. The only reason I'm here again is because I wanted to refresh my mind on what I was doing with this. So, even though it's a couple years late, thank you much!
(Um... I haven't been on LQ for a while and I don't see the "Solved" option in the thread tools anymore. Did they remove this?) |
I also used this information. Thanks!
|
All times are GMT -5. The time now is 02:37 AM. |