Function adas.str2value
def str2value(string, dtype=builtins.int)-
Converts a string to a numerical value.
Parameters
string:str- string representation of value.
dtype:datatype- form of output, defaults to int
Returns
value:intorfloat- numerical value according to dtype.
Notes
Restricted to int and float.
Checks for fortran-style 'D' scientific notation.
Returns 0 if the string is blank; mimicking fortran.
Version History
- Martin O'Mullane, 14-08-2022
- First version
Example
>>> import adas as adas >>> line=" 23 45.0 2.34D-2" >>> adas.str2value(line[0:5]) 23 >>> adas.str2value(line[13:], dtype=float) 0.0234 >>> adas.str2value(line[0:2]) 0