inpDecimal¶
Module Contents¶
- class inpDecimal.inpDecimal(inputStr)¶
Bases:
DecimalAn
inpDecimalobject behaves like a regularDecimal, except it has new attributes_formatStrand 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
Decimalinstance. It also raises anDecimalInfErrorif inputStr contains ‘INF’ (not case-sensitive). ‘INF’ will create a validDecimalobject, but there should be no cases where an infinite number is valid for an Abaqus input file. Thus, an exception is raised which triggersinpRWto handle the input as a string-like object instead of aDecimal.The original inputStr will be passed to
__init__().- Parameters:
inputStr (str) – The string to be processed. Should contain a floating-point like object.
- Raises:
- __init__(inputStr)¶
Creates the
inpDecimalinstance.This is like the
Decimalclass, 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
inpDecimalinherits fromDecimal, they support the same operations. Note that the resultant of most operations between twoinpDecimalobjects will be aDecimal, as shown in the following example:>>> b = inpDecimal(' 2') >>> a * b Decimal('6.28')
Operations between an
inpDecimaland afloatwill raise aTypeError, 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
_formatExpand_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:
- __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__()¶
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:
- __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)