Personal tools
You are here: Home CDAT Tips and Tricks File I/O Tips Opening data file.
Document Actions

Opening data file.


  Table of Contents Previous Next
Contents Previous Next

Goal: Learn how to open a file in CDAT.


Opening file syntax:

fileobj = cdms.open(String path, String mode)
Open the file specified by path returning a CdmsFile object.
path is the file pathname, a string.
mode is the open mode indicator, as listed in the table below:
   'r'
 read - only
   'r+'  
 read-write
   'a'
 read-write. Open the file if it exists, otherwise create a new file.
   'w'
 create a new file, read-write.


Opening a self-describing file for reading

import cdms 
f = cdms.open(file_name)
It will open an existing file protected against writing


Opening a new file for writing

f = cdms.open(file_name,’w’)

It will create a new file even if it already exists


Opening an existing file for writing

f = cdms.open(file_name,’r+’) # or‘a’

It will open an existing file ready for writing or reading
 
  Table of Contents Previous Next
Contents Previous Next

Powered by Plone