diff options
author | pierregm <pierregm@localhost> | 2010-05-16 23:05:30 +0000 |
---|---|---|
committer | pierregm <pierregm@localhost> | 2010-05-16 23:05:30 +0000 |
commit | 97a38c4a4233fb133b2f2fa8b4fad9e65657f572 (patch) | |
tree | 70a91968a539cfbae47c8d6553fa75886c69ccf9 /numpy/lib/_iotools.py | |
parent | ccf308399107ec304b7e0d36692f9d929b6d3416 (diff) | |
download | numpy-97a38c4a4233fb133b2f2fa8b4fad9e65657f572.tar.gz |
* add a `replace_space` option to NameValidator
* Force a file to be opened in 'U' mode (bug #1473)
Diffstat (limited to 'numpy/lib/_iotools.py')
-rw-r--r-- | numpy/lib/_iotools.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/numpy/lib/_iotools.py b/numpy/lib/_iotools.py index b2a7d4729..c9d81048f 100644 --- a/numpy/lib/_iotools.py +++ b/numpy/lib/_iotools.py @@ -258,6 +258,8 @@ class NameValidator: * If 'lower', field names are converted to lower case. The default value is True. + replace_space: '_', optional + Character(s) used in replacement of white spaces. Notes ----- @@ -281,7 +283,8 @@ class NameValidator: defaultexcludelist = ['return', 'file', 'print'] defaultdeletechars = set("""~!@#$%^&*()-=+~\|]}[{';: /?.>,<""") # - def __init__(self, excludelist=None, deletechars=None, case_sensitive=None): + def __init__(self, excludelist=None, deletechars=None, + case_sensitive=None, replace_space='_'): # Process the exclusion list .. if excludelist is None: excludelist = [] @@ -303,6 +306,8 @@ class NameValidator: self.case_converter = lambda x: x.lower() else: self.case_converter = lambda x: x + # + self.replace_space = replace_space def validate(self, names, defaultfmt="f%i", nbfields=None): """ @@ -347,14 +352,16 @@ class NameValidator: deletechars = self.deletechars excludelist = self.excludelist case_converter = self.case_converter + replace_space = self.replace_space # Initializes some variables ... validatednames = [] seen = dict() nbempty = 0 # for item in names: - item = case_converter(item) - item = item.strip().replace(' ', '_') + item = case_converter(item).strip() + if replace_space: + item = item.replace(' ', replace_space) item = ''.join([c for c in item if c not in deletechars]) if item == '': item = defaultfmt % nbempty |