Package Scientific :: Package IO :: Module FortranFormat :: Class FortranLine

[frames] | no frames]

# Class FortranLine

Fortran-style record in formatted files

FortranLine objects represent the content of one record of a Fortran-style formatted file. Indexing yields the contents as Python objects, whereas transformation to a string (using the built-in function 'str') yields the text representation.

Restrictions:

1. Only A, D, E, F, G, I, and X formats are supported (plus string constants for output).
2. No direct support for complex numbers; they must be split into real and imaginary parts before output.
3. No overflow check. If an output field gets too large, it will take more space, instead of being replaced by stars according to Fortran conventions.

Instance Methods

__getitem__(self, i) Returns: the ith data element |

__getslice__(self, i, j) Returns: a list containing the ith to jth data elements |

__init__(self, line, format, length=80) |

`int`

__len__(self) Returns: the number of data elements in the record |

`str`

__str__(self) Returns: a Fortran-formatted text representation of the data record |

`bool`

isBlank(self) Returns: `True` if the line contains only whitespace |

Method Details

### __getitem__(self, i)
(Indexing operator)

Parameters:
  - `i` (`int`) - index
Returns:
  the ith data element

### __getslice__(self, i, j)
(Slicling operator)

Parameters:
  - `i` (`int`) - start index
  - `j` (`int`) - end index
Returns:
  a list containing the ith to jth data elements

### __init__(self, line, format, length=80)
(Constructor)

Parameters:
  - `line` - either a sequence of Python objects, or a string formatted according to Fortran rules
  - `format` - either a Fortran-style format string, or a FortranFormat object. A FortranFormat should be used when the same format string is used repeatedly, because then the rather slow parsing of the string is performed only once.
  - `length` - the length of the Fortran record. This is relevant only when data is a string; this string is then extended by spaces to have the indicated length. The default value of 80 is almost always correct.

### __len__(self)
(Length operator)

Returns: `int`
  the number of data elements in the record

### __str__(self)
(Informal representation operator)

Returns: `str`
  a Fortran-formatted text representation of the data record

### isBlank(self)

Returns: `bool`
  `True` if the line contains only whitespace