Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #84994

Re: CSV and number formats

References <maki32$iav$1@ger.gmane.org>
Date 2015-02-01 07:50 -0600
Subject Re: CSV and number formats
From Skip Montanaro <skip.montanaro@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.18359.1422798626.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Feb 1, 2015 at 12:45 AM, Frank Millman <frank@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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: CSV and number formats Skip Montanaro <skip.montanaro@gmail.com> - 2015-02-01 07:50 -0600

csiph-web