inpString

Module Contents

class inpString.inpString(inputStr, ss=False)

Bases: str

An inpString object behaves like a regular str, except it will internally store the string value without any leading or trailing spaces (Abaqus is space-insensitive regarding leading or trailing spaces in names). This class will track the leading and trailing spaces using interned string patterns, which will be used to reproduce the original string exactly.

static __new__(inputStr, ss=False)
__init__(inputStr, ss)

Creates the inpString instance.

This is meant to operate on text which corresponds to a single string item. For example, a set name, a parameter name, etc. Thus, in most cases inputStr should be a single word with surrounding whitespace. The only time inputStr should contain a space between alphanumeric characters is when the value of interest is a quoted string and includes spaces between words.

Example usage:

>>> from inpString import inpString
>>> inpString('  Nodeset-1')
inpString('  Nodeset-1', False)

If we desire to remove trailing and leading spaces, we can set ss = True:

>>> inpString('  Nodeset-1', ss=True)
inpString('Nodeset-1', True)
Parameters:
  • inputStr (str) – The unformatted string for which the inpString will be created.

  • ss (bool) – If True, leading and trailing spaces will be removed from inputStr, and not reinserted when producing the output string.

ss

If True, leading and trailing spaces will be permanently removed from inputStr. Defaults to False.

Type:

bool

_value

Stores the non-whitespace information of inputStr. Defaults to None

_formatStr

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

_evalString(inputStr)

_evalString(inputStr)

Evaluates the input string and performs some formatting. This will separate whitespace from alphanumeric characters, but it will leave spaces between alphanumeric characters.

This will set _value and _formatStr, but the function has no direct return.

Here’s an example of the _value and _formatStr attributes for a simple case:

>>> from inpString import inpString
>>> s1 = inpString('  Nodeset-1')
>>> s1._value
'Nodeset-1'
>>> s1._formatStr
'  %s'

Here are the same attributes when ss = True:

>>> s2 = inpString('  Nodeset-1', ss=True)
>>> s2._value
'Nodeset-1'
>>> s2._formatStr
'%s'

Finally, if we have a quoted string with spaces, the spaces inside the quotes are included with _value because they’re meaningful. The spaces outside the quotes are tracked in _formatStr as usual:

>>> s3 = inpString('  "Nodeset Name with Spaces"')
>>> s3._value
'"Nodeset Name with Spaces"'
>>> s3._formatStr
'  %s'
_outstr()

Generates the output string. _value is subbed into _formatStr. Should not need to be called by the user directly.

Example usage:

>>> from inpString import inpString
>>> s = inpString('  Nodeset-1')
>>> s._outstr()
'  Nodeset-1'

This function can also handle cases where inputStr to __init__() was only whitespace:

>>> s = inpString('    ')
>>> s._outstr()
'    '
Returns:

The string in the original formatting.

Return type:

str

__str__()

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

Example usage:

>>> from inpString import inpString
>>> print(inpString('  Nodeset-1'))
  Nodeset-1
Return type:

str

__repr__()

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

Example usage:

>>> from inpString import inpString
>>> inpString('  Nodeset-1')
inpString('  Nodeset-1', False)
Return type:

str

__getnewargs__()

__getnewargs__():

This function is required so the class can pickle/unpickle properly. This enables multiprocessing, and should not need to be called by the user.

Example usage:

>>> from inpString import inpString
>>> s = inpString('  Nodeset-1')
>>> s.__getnewargs__()
('  Nodeset-1', False)
__weakref__

list of weak references to the object (if defined)