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


Groups > comp.lang.python > #84994 > unrolled thread

Re: CSV and number formats

Started bySkip Montanaro <skip.montanaro@gmail.com>
First post2015-02-01 07:50 -0600
Last post2015-02-01 07:50 -0600
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#84994 — Re: CSV and number formats

FromSkip Montanaro <skip.montanaro@gmail.com>
Date2015-02-01 07:50 -0600
SubjectRe: CSV and number formats
Message-ID<mailman.18359.1422798626.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web