CSV and number formats

Skip Montanaro skip.montanaro at gmail.com
Sun Feb 1 08:50:22 EST 2015


On Sun, Feb 1, 2015 at 12:45 AM, Frank Millman <frank at chagford.com> wrote:
> Is this a recognised format, and is there a standard way of parsing it? If
> not, I will have to special-case it, but I would prefer to avoid that if
> possible.

Doesn't look "standard" to me in any fashion. You shouldn't need to
special case it though, just

 s = re.sub("^[+]0*", "", s)

e.g.,

>>> s = '+00000-21.45'
>>> t = '+0000021.45'
>>> re.sub("^[+]0*", "", s)
'-21.45'
>>> re.sub("^[+]0*", "", t)
'21.45'

That should work on all numbers, not just the weird one. Unless you
have bazillions of numbers, it shouldn't be a performance hit either.

Skip



More information about the Python-list mailing list