How to store numeric array in disk

Janko Hauser jhauser at ifm.uni-kiel.de
Fri Apr 27 06:03:11 EDT 2001


"Tawee Laoitichote" <astpspd at pea.or.th> writes:

> py> myfile='h:\\python21\\prob.pik'
> py> print myfile
> h:\python21\prob.pik
> py> p=pickle.Pickler(myfile)
> Traceback (most recent call last):
>   File "<pyshell#61>", line 1, in ?
>     p=pickle.Pickler(myfile)
>   File "h:\python21\lib\pickle.py", line 104, in __init__
>     self.write = file.write
> AttributeError: write
> 
> my next statement should be p.dump(mystuff) #which is my array stuff
> 
> What am I doing wrong? Please suggest...
> 

myfile should be an opened file object like

py> myfile=open('h:\\python21\\prob.pik','rb')

Are you using the standard array or arrays from the NumPy package?
If mystuff are NumPy arrays there are special functions to pickle
these to disk, like DumpArray or LoadArray.

HTH,
__Janko
-- 
  Institut fuer Meereskunde             phone: 49-431-597 3989
  Dept. Theoretical Oceanography        fax  : 49-431-565876
  Duesternbrooker Weg 20                email: jhauser at ifm.uni-kiel.de
  24105 Kiel, Germany



More information about the Python-list mailing list