1.1 --- a/simplex/readers.py Sat Oct 01 15:07:17 2011 +0200
1.2 +++ b/simplex/readers.py Sat Oct 01 16:01:22 2011 +0200
1.3 @@ -35,20 +35,25 @@
1.4
1.5 "An accessor using a delimiter to split a record."
1.6
1.7 - def __init__(self, keys=None, delimiter=None):
1.8 + def __init__(self, keys=None, delimiter=None, numeric=0):
1.9
1.10 """
1.11 Initialise the accessor using a sequence of 'keys' indicating the
1.12 columns in each record that provide the values in the eventual compound
1.13 key provided by each record, along with a 'delimiter' indicating how
1.14 - such columns are identified.
1.15 + such columns are identified. If 'numeric' is set to a true value, keys
1.16 + will be interpreted as numbers.
1.17 """
1.18
1.19 self.keys = keys or [0]
1.20 self.delimiter = delimiter
1.21 + self.convert = numeric and self.convert_numeric or (lambda x: x)
1.22 +
1.23 + def convert_numeric(self, term):
1.24 + return map(int, term)
1.25
1.26 def get_key(self, record):
1.27 values = record.split(self.delimiter)
1.28 - return [values[key] for key in self.keys]
1.29 + return self.convert([values[key] for key in self.keys])
1.30
1.31 # vim: tabstop=4 expandtab shiftwidth=4