0

I have array of floats written to a file. I need to read contents of this file and pass it as argument to another function. The problem is that on read from a file I receive a String. How do I convert from String to [Float]?

This is how I read from file:

import os
import matplotlib.pyplot as plt

filepath = "/pathToFile"
file = open(filePath, "r")

rawString = file.read()
#rawString is like '[569.675049, 706.275879, 776.753418, 785.674805]'

#somehow process rawString
processedArray = process(rawString)

plt.plot(processedArray)
plt.show()
3
  • Do you have access to the NumPy library? Because it has useful functions to read in data Commented Jan 3, 2018 at 12:53
  • @DavidG Yes, I do have access to this lib. Commented Jan 3, 2018 at 12:54
  • 1
    numpy.loadtxt might be useful Commented Jan 3, 2018 at 12:55

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.