Strings, Integers, and Decimals¶
One option with inpRW is the preserveSpacing parameter. If this is True, inpRW will track every space character,
and the exact formatting of every number for every piece of data parsed from the input file.
Since a float cannot accurately represent numbers with decimal points (reference),
inpRW has a parameter (useDecimal) to convert all numbers that would be evaluated to float to Decimal instead.
Setting useDecimal to False will treat numbers as float; this will result in faster performance, but some formatting and value
precision will be lost. If useDecimal = True, inpRW will use floats in one location: pd. [1]
However, using Decimal is not enough by itself to exactly reproduce an input file. Converting a string into
its underlying data type will naturally lose spaces and exact formatting of the original number, so inpRW uses a custom eval()
function (eval2()), and 3 new classes: inpDecimal, inpInt, and inpString. These
functions track the exact spacing and number formatting in the original item and store that information in the _formatStr
and _formatExp attributes of the new items. These classes inherit from Decimal, int, and
str, and should support all the same operations as their base classes. Please see those class definitions for more details.
Creating an instance of inpRW with preserveSpacing = False, useDecimal = True will not preserve the exact spacing, and will instead create
Decimal, int, and str items. Using preserveSpacing = False, useDecimal = False will use float,
int, and str items. Using preserveSpacing = True, useDecimal = True will preserve the exact spacing and use inpDecimal,
inpInt, and inpString.
Throughout this documentation (and particularly the API Reference section), there will be references to str,
int, and Decimal. In almost all cases, these classes can be used interchangeably with the inp* variant.
Footnotes