NRAO Home > CASA > CASA Cookbook and User Reference Manual

B.4 Lists and Ranges

Sometimes, you need to give a task a list of indices. For example, some tasks and tools expect a comma-separated Python list, e.g.

     scanlist = [241, 242, 243, 244, 245, 246]

You can use the Python range function to generate a list of consecutive numbers, e.g.

     scanlist = range(241,247)

giving the same list as above, e.g.

CASA <1>: scanlist=range(241,247)  
CASA <2>: print scanlist  
[241, 242, 243, 244, 245, 246]

Note that range starts from the first limit and goes to one below the second limit (Python is 0-based, and range is designed to work in loop functions). If only a single limit is given, the first limit is treated as 0, and the one given is used as the second, e.g.

CASA <3>: iflist=range(4)  
CASA <4>: print iflist  
[0, 1, 2, 3]

You can also combine multiple ranges by summing lists

CASA <5>: scanlist=range(241,247) + range(251,255)  
CASA <6>: print scanlist  
[241, 242, 243, 244, 245, 246, 251, 252, 253, 254]


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