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


Groups > comp.lang.python > #98415

Re: Converting a string into a float that includes the negative

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From MRAB <python@mrabarnett.plus.com>
Newsgroups comp.lang.python
Subject Re: Converting a string into a float that includes the negative
Date Sun, 8 Nov 2015 02:40:24 +0000
Lines 33
Message-ID <mailman.116.1446950434.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 8bit
X-Trace news.uni-berlin.de JCapecA2MoYQjnX3M62wOQJmWyosB4jyeWmsw2IQVo+w==
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'float': 0.05; 'literal': 0.09; 'msg:': 0.09; 'negative,': 0.09; 'subject:into': 0.09; 'subject:string': 0.09; 'def': 0.13; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:Converting': 0.16; 'wrote:': 0.16; 'string': 0.17; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; 'converting': 0.27; 'subject:that': 0.29; 'print': 0.30; 'false': 0.35; 'should': 0.36; 'there': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'doing': 0.38; 'wrong': 0.38; 'end': 0.39; 'skip:- 20': 0.39; 'subject:the': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'email addr:gmail.com': 0.62; 'world': 0.64; 'longitude': 0.84; 'gps': 0.91; 'league': 0.91
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=CvRCCSMD c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=EBOSESyhAAAA:8 a=IkcTkHD0fZMA:10 a=pGLkceISAAAA:8 a=H0uReWjCvFCaHMAyYscA:9 a=QEXdDO2ut3YA:10
X-AUTH mrabarnett@:2500
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0
In-Reply-To <2ced12ff-ae0c-4e86-ac38-357558251e51@googlegroups.com>
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:98415

Show key headers only | View raw


On 2015-11-08 02: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]"
>
> def contains_words(word,msg):
> 	if word in msg:
> 		return true
> 	else:
> 		return false
> 		
> def get_tweet(tweet_line):
> 	part_list = tweet_line.split('\t')
> 	tweet = part_list[3]
> 	return tweet
>
> def get_longitude(tweet_line):
> 	part_list = tweet_line.split('\t')
> 	gps = part_list[0]
> 	gps_list = gps.split(', ')
> 	long = gps_list[1]
> 	long1 = long[1:]
> 	longitude = float(long1)
> 	return longitude
>
> a = get_longitude("[41.3, -81.4]\t6\t2011-08-28 19:02:28\tyay. little league world series!")
> print a
>
> the answer should be
> get_longitude("[41.3, -81.4]\t6\t2011-08-28 19:02:28\tyay. little league world series!") → -81.4
>
You're slicing the wrong end off 'long'.

You have '-81.4]'. You want '-81.4'. You should be doing long[ : -1].

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


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