PDA

View Full Version : Reading values from a file using Python



adamsnative
February 26th, 2009, 01:12 PM
hi

Suppose i have stored an array in a file.How can i read that array in my current program and manipulate it ie if i read an integer array i manipulate it using the same method by which i manipulate a local array declared in my program , because i want to access the individual values of the array read from the file row and column wise
Please help
Thank you

ssam
February 26th, 2009, 01:23 PM
if it is a nice neat array of numbers (each row having the same number of numbers), then the best option would be to use numpy/scipy

http://www.scipy.org/Cookbook/InputOutput

if you are working with arrays of numbers using a numpy array will be quicker and easier than using a list of lists.

ghostdog74
February 26th, 2009, 02:18 PM
you can use pickle/shelve/cpickle. check the documentation.

adamsnative
February 26th, 2009, 03:07 PM
thans any further help will b of gr8 use and aapreciated it will be gr8 if you can post an example with the output also
thanks a lot

Paul Miller
February 27th, 2009, 07:14 AM
How to get your data back into Python depends entirely on how you wrote it out. Provide a small example showing what you did to write the array to disk in the first place, and then we can help you read it back.

adamsnative
February 27th, 2009, 11:46 AM
i am having the values of 7 haralik parameters for 20 images and i want to store these values as and when i get in a file and then retreive the whole lot at a time in an array ie a floating point array