The Autoconverter class was taken and slightly adapted from RecSQL, recsql.converter. It is mainly used by gromacs.fileformats.xpm.XPM to automagically generate useful NumPy arrays from xpm files. Custom conversions beyond the default ones in Autoconverter can be provided with the constructor keyword mapping.
Automatically convert an input value to a special python object.
The Autoconverter.convert() method turns the value into a special python value and casts strings to the “best” type (see besttype()).
The defaults for the conversion of a input field value to a special python value are:
value python ‘---‘ None ‘’ None ‘True’ True ‘x’ True ‘X’ True ‘yes’ True ‘Present’ True ‘False’ False ‘-‘ False ‘no’ False ‘None’ False ‘none’ False
If the sep keyword is set to a string instead of False then values are split into tuples. Probably the most convenient way to use this is to set sep = True (or None) because this splits on all white space whereas sep = ‘ ‘ would split multiple spaces.
Initialize the converter.
Arguments : |
|
---|
Convert x (if in the active state)
If set to True then conversion takes place; False just returns besttype() applid to the value.
Toggle the state of the Autoconverter. True uses the mode, False does nothing
Convert string x to the most useful type, i.e. int, float or unicode string.
If x is a quoted string (single or double quotes) then the quotes are stripped and the enclosed string returned.
Note
Strings will be returned as Unicode strings (using unicode()), based on the encoding argument, which is “utf-8” by default.
Convert obj to unicode (if it can be be converted)