[Numpy-discussion] creating or truncating SD files in pyhdf

Catherine Moroney Catherine.M.Moroney@jpl.nasa....
Thu Sep 11 15:54:49 CDT 2008


What is the correct way to create an SD file (if it doesn't already  
exist),
or truncate and then rewrite an existing one?  Does it matter which  
order
the file-access options are set?

For instance, here's my code:

self.flhdf_stereo = SD.SD(flname_stereo, \
                           SD.SDC.TRUNC|SD.SDC.WRITE|SD.SDC.CREATE)

and this fails if the file already exists, complaining that it can't  
open
the path, even though the path is valid.  This is the case if the file
already exists.

If the file doesn't exist, then it works just fine.  Additionally, if
I remove the "TRUNC" option then the file is opened without any  
problems.

However, I need to truncate the file if it already exists.  How do I do
this?

Catherine









More information about the Numpy-discussion mailing list