Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98454
| Path | csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Pete Dowdell <contact@stridebird.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Converting a string into a float that includes the negative |
| Date | Sun, 8 Nov 2015 09:39:00 +0700 |
| Lines | 20 |
| Message-ID | <mailman.129.1446996900.16136.python-list@python.org> (permalink) |
| References | <2ced12ff-ae0c-4e86-ac38-357558251e51@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de WJAC0zkbjp0dHbAF7LRYpw6GrqRpMZ3PxlMWvY8dBbzQ== |
| Return-Path | <contact@stridebird.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'string.': 0.04; 'float': 0.05; 'line:': 0.07; 'exception:': 0.09; 'literal': 0.09; 'negative,': 0.09; 'subject:into': 0.09; 'subject:string': 0.09; 'bracket': 0.16; 'received:192.168.8': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Converting': 0.16; 'wrote:': 0.16; 'string': 0.17; '>>>': 0.20; 'fix': 0.21; 'trying': 0.22; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'error': 0.27; 'converting': 0.27; 'subject:that': 0.29; 'received:google.com': 0.35; 'there': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'received:209.85.220': 0.38; 'end': 0.39; 'skip:- 20': 0.39; 'subject:the': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'email addr:gmail.com': 0.62; 'world': 0.64; 'cast': 0.66; 'from:addr:contact': 0.66; 'square': 0.76; 'casting': 0.84; 'league': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=stridebird_com.20150623.gappssmtp.com; s=20150623; h=from:subject:to:references:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=q/Do+8RJIIQfpfBNOcDAjew60GO6X79+hz2DutM4Oi8=; b=HWPQwPtJYG9EU3B1cXldLontW5AnpfoaH/MCTJer0KdZbXaJJK5Dx8cZJ06VV/ePkq u52wM6I4Dxk8XeOH4sDjKYXW72HtTLNZCEQA8sZddjUADOhUCdhSTd24xjoE51TJ0ZQW JVjhy67bARSveEQbP4nRYZTr0FyKLXRHk6w3pgS00L8WYSvr7MHAvl5rkk1Veo9yF7qe y5osLccG93WEupVTXhJJWYAt7+9dr1JCyA1dD0XimcO3bmoxEQNkffSyJVbVnibjw2vf WXS/a5ELhBwaQLhZv+ilFsJl1nepGWwA6MRMW7K9u1ckri1k850LteHssWCcOaffFJTI XXWQ== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:subject:to:references:message-id:date :user-agent:mime-version:in-reply-to:content-type :content-transfer-encoding; bh=q/Do+8RJIIQfpfBNOcDAjew60GO6X79+hz2DutM4Oi8=; b=STtq2CfnUqqaf6zFyZzDSiGPMEQxKGNAGj8I/ZQWkBpS7btXR85gz+CxMUUQue2mY/ 8wIhGCQ0qf2R6YVyAJYH/DCV9iORweSgbWXhJ6y2VdZjhfC5fkYlvbJsg2q4NlksobhQ QLvHxFvVu+3obL27/vjGMadibRnwRO6lYUJYNf8T7t9LtlJcUrOrf4JWSbjIAjbqkFAZ 8GlG2SUGPNfqUv/DLxuJLPuANfpQcqHchrRHsFe2/o0A6kIPtTbvrp682nMOKLQu2nzJ L8SjQnACuLMKJg7V9WaNXdHoeStK5c+MSEk1ekACWyAi6pfnzuFEghCAXqFOpj5H1F9J ifWQ== |
| X-Gm-Message-State | ALoCoQnAn0D7bGoZNSmm2kQ69jzTmzcjf/hjtyZA+33SMWWf4eAAmQf94RIRGJNgTQHuUq3s+uyv |
| X-Received | by 10.66.100.166 with SMTP id ez6mr29708638pab.49.1446950344494; Sat, 07 Nov 2015 18:39:04 -0800 (PST) |
| X-Google-Original-From | Pete Dowdell <pete@stridebird.com> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 |
| In-Reply-To | <2ced12ff-ae0c-4e86-ac38-357558251e51@googlegroups.com> |
| X-Mailman-Approved-At | Sun, 08 Nov 2015 10:34:59 -0500 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:98454 |
Show key headers only | View raw
On 08/11/15 09:11, phamtony33@gmail.com wrote:
> I am having issue with converting the string into a float because there is a negative, so only end up with "ValueError: invalid literal for float(): 81.4]"81.4]
The error is right there in the exception: you are trying to cast
'81.4]' - that's a square bracket in the string.
You are also removing the negative sign from your number before casting
with your slice
this will fix it - change line:
long1 = long[1:]
to:
long1 = long[:-1]
test:
>>> TXT="[41.3, -81.4]\t6\t2011-08-28 19:02:28\tyay. little league
world series!"
>>> float( TXT.split('\t')[0].split(', ')[1][:-1] )
-81.4
pd
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Converting a string into a float that includes the negative phamtony33@gmail.com - 2015-11-07 18:11 -0800
Re: Converting a string into a float that includes the negative MRAB <python@mrabarnett.plus.com> - 2015-11-08 02:40 +0000
Re: Converting a string into a float that includes the negative phamtony33@gmail.com - 2015-11-07 18:44 -0800
Re: Converting a string into a float that includes the negative Pete Dowdell <contact@stridebird.com> - 2015-11-08 09:39 +0700
csiph-web