Python equivalent of Matlab textscan

shadonar picture shadonar · Oct 29, 2012 · Viewed 9.7k times · Source

I'm working with transferring some Matlab code to Python. I'm relatively new to Python and am unsure of a Python equivalent of Matlab's textscan method. Any help would be greatly appreciated.

Answer

jorgeca picture jorgeca · Oct 29, 2012

If you're translating Matlab to Python, I'll assume you're already using NumPy.

In that case, you can use np.loadtxt (if no values are missing) or np.genfromtxt (if there are missing values: I'm not sure whether Matlab's textscan handles that).

Give us a few more details if you need more help!