A Fortran binary (unformatted) file object.
A binary Fortran file can be opened using the open method of this module; a File object is returned that supports a writeline method (for writing records), a readline method (for reading records) and the iterator protocol (for reading).
It is normally easier to use the open() factory function rather than construct instances directly.
Arguments
- fd
- The underlying file object, which is typically a file object opened in binary mode.
Read a single signed integer from the file and return it.
If at end-of-file then None is returned. Insufficient data (for example, only 3 bytes remaining but 4 required) will raise some sort of exception.
Return Value
Normally the integer value retrieved from the file. If end-of-file was encountered then``None`` is returned.
Exceptions Raised
- FileTruncatedError
- If the file did not contain a complete integer’s worth of bytes.
Read a single binary record as a string.
Return Value
Normally a string containing the bytes of the record. If end-of-file was encountered then``None`` is returned.
Exceptions Raised
- FileFormatError
- If the record has mismatching record length prefix and suffix markers.
- FileTruncatedError
- If the file did not apparently contain a complete record.
Write a single record to the Fortran binary file.
Arguments
- record
- A string containing the bytes for the record.
Provides itertator protocol support.
This is not normally invoked directly. It is more common to use the idiom
1 2 | for record in myFile:
...
|