Help on module readcol: NAME readcol FILE /devel/goods16/ferguson/pygoodsdist/doc/doctmp/readcol.py DESCRIPTION Routines for reading general whitespace-delimited, column-oriented files. Returned values are either numpy one-dimensional arrays. The read routines parse the input looking for decimal points or non-numeric characters to decide on the format of the output. Reading is therefore a bit slow, but the program interface is extremely simple. For example, if the file 'foo' has three columns, read them in as follows: a,b,c = fgetcols('foo') A few other options: a,b,c,d = fgetcols('foo',1,3,5,7) # Read some selected columns a = fgetcols('foo') # Read all the columns (a is then a tuple of arrays) a,b,c = fgetcols('foo',fs=',') # Change the field separator to a comma a,b,c = fgetcols('foo',cmt='!') # Change the comment character to '!' The module also provides an object-oriented interface to save re-reading the file if multiple getcol calls are desired: f = readcol('foo') a,b = f.getcols(1,2) c,d = f.getcols(3,4) f.close() Ignores comment lines. Ignores blank lines. Optionally changes INDEF to a desired value (e.g. -99.99). As of version 5.0, only numpy is offered (Numeric and numarray used to be options). CLASSES readcol class readcol | Column-oriented file methods. | | Methods defined here: | | __init__(self, cfile, arraytype=, indef='') | Open file, read in all the lines, and return numpy arrays. | | Arguments: | cfile -- file to read | arraytype -- numpy (used to allow Numeric or numarray) | indef -- string replacement for INDEF (e.g. NaN) | | close(self) | Release the memory associated with the lines read by __init__ | | getcol(self, col, fs=None) | Read in a single column (columns start at 1). | | getcols(self, *args, **kwargs) | Read in a multiple columns (columns start at 1). FUNCTIONS fgetcol(cfile, col, arraytype='numpy', cmt='#', indef='-99.99') Read in a single column from a file. Parse the column to determine the type of variable (integer, float, string) and return either an array of that type (int64, float64) or a character array. Arguments: cfile -- file to be read col -- desired column (starting at 1) arraytype -- numpy indef="-99.99" (INDEF replacement string) fgetcols(cfile, *args, **keywords) Read multiple columns from a file. Parse each column to determine the type of variable (integer, float, string) and return either one-dimensional arrays of the appropriate type (int64, float64) or a character array. Arguments: cfile -- file to be read *args -- desired columns (starting at 1) **keywords -- indef="-99.99" (INDEF replacement string) -- cmt="#" (comment character) -- fs=None (field separator; defaults to whitespace) Examples: If the file 'foo' has three columns, read them in as follows: a,b,c = fgetcols('foo') A few other examples: a,b,c,d = fgetcols('foo',1,3,5,7) # read selected columns a = fgetcols('foo') # read all columns a,b,c = fgetcols('foo',fs=',') # Change the field separator a,b,c = fgetcols('foo',cmt='!') # Change the comment character to '!' getcol(col, lines, N, fs=None) Read in a single column from a list of strings. Parse each column to determine the type of variable (integer, float, string) and return either an array of that type (int64, float64) or a character array. Arguments: col -- desired column (starting at 1) lines -- list of strings (one per line) read from input file N -- numpy getfloats(col, lines, values, fs=None) getints(col, lines, values, fs=None) getstrings(col, lines, values, fs=None) remove_comments(l, cmt='#') replace_indef(l, indef) DATA __version__ = '5.0' VERSION 5.0 wrote readcol.html