NRAO Home > CASA > CASA Cookbook and User Reference Manual

B.5 Dictionaries

Python dictionaries are data structures that contain key:value pairs, sort of like a hash array. These are useful to store mini-databases of things. In CASA, the parameter values are kept in a dictionary behind the scenes.

To initialize a dictionary, say we call it mydict, for use:

CASA <7>: mydict = {}

To add members:

CASA <8>: mydict[’source’] = ’0137+331’  
CASA <9>: mydict[’flux’] = 5.4

To see its contents:

CASA <10>: mydict  
  Out[10]: {’flux’: 5.4000000000000004, ’source’: ’0137+331’}  
CASA <11>: print mydict  
{’source’: ’0137+331’, ’flux’: 5.4000000000000004}

To access a specific entry:

CASA <12>: print mydict[’flux’]  
5.4

  B.5.1 Saving and Reading Dictionaries


More information about CASA may be found at the CASA web page

Copyright © 2010 Associated Universities Inc., Washington, D.C.

This code is available under the terms of the GNU General Public Lincense


Home | Contact Us | Directories | Site Map | Help | Privacy Policy | Search