class NameValidator:
Object to validate a list of strings to use as field names.
The strings are stripped of any non alphanumeric character, and spaces are replaced by '_'. During instantiation, the user can define a list of names to exclude, as well as a list of invalid characters. Names in the exclusion list are appended a '_' character.
Once an instance has been created, it can be called with a list of
names, and a list of valid names will be created. The __call__
method accepts an optional keyword "default" that sets the default name
in case of ambiguity. By default this is 'f', so that names will
default to f0
, f1
, etc.
file
becomes file_
if supplied.The default value is True.
Calling an instance of NameValidator
is the same as calling its
method validate
.
>>> validator = np.lib._iotools.NameValidator() >>> validator(['file', 'field2', 'with space', 'CaSe']) ('file_', 'field2', 'with_space', 'CaSe')
>>> validator = np.lib._iotools.NameValidator(excludelist=['excl'], ... deletechars='q', ... case_sensitive=False) >>> validator(['excl', 'field2', 'no_q', 'with space', 'CaSe']) ('EXCL', 'FIELD2', 'NO_Q', 'WITH_SPACE', 'CASE')
Method | __call__ |
Undocumented |
Method | __init__ |
Undocumented |
Method | validate |
Validate a list of strings as field names for a structured array. |
Class Variable | defaultdeletechars |
Undocumented |
Class Variable | defaultexcludelist |
Undocumented |
Instance Variable | case_converter |
Undocumented |
Instance Variable | deletechars |
Undocumented |
Instance Variable | excludelist |
Undocumented |
Instance Variable | replace_space |
Undocumented |
Undocumented
Validate a list of strings as field names for a structured array.
A NameValidator
instance can be called directly, which is the
same as calling validate
. For examples, see NameValidator
.