inpDecimal

Module Contents

class inpDecimal.inpDecimal(inputStr)

Bases: Decimal

An inpDecimal object behaves like a regular Decimal, except it has new attributes _formatStr and possibly _formatExp. These attributes are used to create exact string representations of the original object.

static __new__(inputStr)

This function processes the inputStr and handles some problematic strings.

It replaces ‘d’ and ‘D’ characters in inputStr prior to creating the base Decimal instance. It also raises an DecimalInfError if inputStr contains ‘INF’ (not case-sensitive). ‘INF’ will create a valid Decimal object, but there should be no cases where an infinite number is valid for an Abaqus input file. Thus, an exception is raised which triggers inpRW to handle the input as a string-like object instead of a Decimal.

The original inputStr will be passed to __init__().

Parameters:

inputStr (str) – The string to be processed. Should contain a floating-point like object.

Raises:

inpRWErrors.DecimalInfError

__init__(inputStr)

Creates the inpDecimal instance.

This is like the Decimal class, except it also tracks the exact formatting of the original number string.

Parameters:

inputStr (str) – The string representing the number which should be parsed.

Examples

>>> from inpDecimal import inpDecimal
>>> a = inpDecimal('  3.14e0')
>>> str(a)
'  3.14e0'

Since inpDecimal inherits from Decimal, they support the same operations. Note that the resultant of most operations between two inpDecimal objects will be a Decimal, as shown in the following example:

>>> b = inpDecimal(' 2')
>>> a * b
Decimal('6.28')

Operations between an inpDecimal and a float will raise a TypeError, as expected:

>>> a * 2.0
Traceback (most recent call last):
    ...
TypeError: unsupported operand type(s) for *: 'inpDecimal' and 'float'
_formatExp

Stores the exponent string if the original number string is in scientific notation. Defaults to None

_formatStr

Stores the whitespace information of inputStr, with placeholder symbols (“%s”) where digits should be reinserted. Defaults to None

_evalDecimal(inputStr)

Parses inputStr to recognize the numeric value and the original formatting.

This function will populate _formatExp and _formatStr, but it has no direct return. It will be called as part of __init__() and should not be called by itself.

Example usage:

>>> from inpDecimal import inpDecimal
>>> a = inpDecimal('  1.234E-2')

This will set the following additional attributes, which track the exact formatting:

>>> a._formatStr
'  %s.%s%s%sE%s'
>>> a._formatExp
'-2'

It also handles numbers which use “d” or “D” for the exponent notation:

>>> inpDecimal('5.678d+10')
inpDecimal('5.678d+10')
Parameters:

inputStr (str) – The string representing the number which should be parsed.

_outstr()

Generates the output string. This should not be called by the user directly, as it is called automatically by __repr__() and __str__().

Example usage:

>>> from inpDecimal import inpDecimal
>>> str(inpDecimal(' 1.234'))
' 1.234'
Returns:

The string in the original formatting.

Return type:

str

__repr__()

Creates a string representation which can be used to recreate the object.

Example

>>> from inpDecimal import inpDecimal
>>> inpDecimal('  -01.097 ')
inpDecimal('  -01.097 ')
Return type:

str

__str__()

Calls _outstr() to create a string of object in the original formatting.

Example

>>> from inpDecimal import inpDecimal
>>> str(inpDecimal('\t-01.097 '))
'\t-01.097 '
Return type:

str

__reduce__()

This function is required so the class can pickle/unpickle properly. This enables multiprocessing.

Example

>>> from inpDecimal import inpDecimal
>>> inpDecimal('5.678D+10').__reduce__()
(<class 'inpDecimal.inpDecimal'>, ('5.678D+10',))
__weakref__

list of weak references to the object (if defined)