|
From: Faheem M. <fa...@fa...> - 2012-03-31 18:18:51
|
Hi
I'm trying to use configobj's validate module to validate and convert
a list of lists of integers.
However, it is not working. The value is
model = [[5, 6], [7, 13, 18], [9, 22], [10, 12], [15, 16, 17], [20, 21]]
I call the validation like
model = check_list_of_list_of_integers
Here is the check function and the error below.
#####################################################################
def list_of_list_of_integers(value):
print "value", value
print "type(value)", type(value)
l = eval(value)
try:
list(l)
except:
raise "error"
return l
fdict = {'check_list_of_list_of_integers': list_of_list_of_integers}
validator = validate.Validator(fdict)
######################################################################
I'm calling 'eval' on the value, which might not be the best idea, but
should work if the value is a string. However, the value is converted
to a list of strings on entrance to the "list_of_list_of_integers"
function, even though I have not asked for it to be so converted.
Any idea what is going on and how I can fix this?
Please CC me on any reply. Thanks.
Regards, Faheem Mitha
value ['[[5', '6]', '[7', '13', '18]', '[9', '22]', '[10', '12]', '[15',
'16', '17]', '[20', '21]]']
type(value) <type 'list'>
Traceback (most recent call last):
File "load_crossval.py", line 29, in <module>
conf = get_conf()
File "/home/faheem/corrmodel/utils.py", line 70, in get_conf
results = config.validate(validator, preserve_errors=True)
File "/usr/lib/pymodules/python2.6/configobj.py", line 2295, in validate
check = self.validate(validator, preserve_errors=preserve_errors,
copy=copy, section=section[entry])
File "/usr/lib/pymodules/python2.6/configobj.py", line 2251, in validate
missing, ret_true, ret_false)
File "/usr/lib/pymodules/python2.6/configobj.py", line 2190, in
validate_entry
missing=missing
File "/usr/lib/pymodules/python2.6/validate.py", line 597, in check
return self._check_value(value, fun_name, fun_args, fun_kwargs)
File "/usr/lib/pymodules/python2.6/validate.py", line 629, in
_check_value
return fun(value, *fun_args, **fun_kwargs)
File "/home/faheem/corrmodel/utils.py", line 46, in
list_of_list_of_integers
l = eval(value)
TypeError: eval() arg 1 must be a string or code object
|