Changeset 3424


Ignore:
Timestamp:
14/02/08 21:36:34 (11 years ago)
Author:
astephen
Message:

Reverted to na_dict being passed in to init method

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nappy/trunk/nappy/na_file/na_file.py

    r3414 r3424  
    4646    """ 
    4747 
    48     def __init__(self, filename, mode="r"):  
     48    def __init__(self, filename, mode="r", na_dict={}):  
    4949        """ 
    5050        Initialization of class, decides if user wishes to read or write 
     
    5555        self._open(mode) 
    5656        self.mode = mode 
     57        self.na_dict = na_dict 
    5758 
    5859        if self.mode == "r": 
     
    7172        self.is_open = True 
    7273 
    73     def write(self, na_dict, delimiter="    ", float_format="%8.3f"): 
    74         """ 
    75         Writes an na_dict to the file and then flushes it to ensure data not  
     74    def write(self, delimiter="    ", float_format="%8.3f"): 
     75        """ 
     76        Writes an na_dict to the file and then flushes it to ensure data not  
    7677        being buffered. 
    77         """ 
     78        """  
    7879        self.delimiter = delimiter 
    7980        self.float_format = float_format 
    8081        # Raise errors if dangerous behaviour 
    81         if self.mode != "w": 
     82        if self.mode != "w": 
    8283            raise Exception("WARNING: Cannot write to read-only file. Can only write to NA file object when mode='w'.") 
    8384 
     
    8990    
    9091        # Parse na_dict then write header and data 
    91         self._parseDictionary(na_dict) 
     92        self._parseDictionary(self.na_dict) 
    9293        self.header = StringIO.StringIO() 
    9394        self.writeHeader() 
     
    9899        self.data_written = True 
    99100          
    100       
    101101    def close(self): 
    102102        "Wrapper to builtin close file function." 
     
    104104        self.is_open = False 
    105105 
    106     def _parseDictionary(self, na_dict): 
     106    def _parseDictionary(self): 
    107107        """ 
    108108        Parser for the optional na_dict argument containing a dictionary 
     
    110110        with the name used in the NASA Ames documentation. 
    111111        """ 
    112         self.na_dict = na_dict 
    113112        for i in self.na_dict.keys(): 
    114113            setattr(self, i, self.na_dict[i]) 
Note: See TracChangeset for help on using the changeset viewer.