I have some complex input to parse (with regexps), and I would like to
create nice objects directy from them.
The re module doesn't of course try to conver to any type, so I was
playing around to see if it's worth do something as below, where I
assign a constructor to every regexp and build an object from the
result..
Do you think it makes sense in general or how do you cope with this problem?
import re
from time import strptime
TIME_FORMAT_INPUT = '%m/%d/%Y %H:%M:%S'
andrea crotti wrote:
> I have some complex input to parse (with regexps), and I would like to
> create nice objects directy from them.
> The re module doesn't of course try to conver to any type, so I was
> playing around to see if it's worth do something as below, where I
> assign a constructor to every regexp and build an object from the
> result..
> Do you think it makes sense in general or how do you cope with this
> problem?
> import re
> from time import strptime
> TIME_FORMAT_INPUT = '%m/%d/%Y %H:%M:%S'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/re.py", line 322, in scan
action = action(self, m.group())
File "<stdin>", line 2, in <lambda>
File "/usr/lib/python2.7/_strptime.py", line 325, in _strptime
(data_string, format))
ValueError: time data '456 07' does not match format '%m/%d/%Y %H:%M:%S'