Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsreader4.netcologne.de!news.netcologne.de!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; '21,': 0.09; '>>>>': 0.09; 'received:209.85.160.174': 0.09; 'received:mail- gy0-f174.google.com': 0.09; 'valueerror:': 0.09; 'float': 0.13; 'wrote:': 0.15; '10:': 0.16; 'int(x)': 0.16; 'integer.': 0.16; 'subject:Convert': 0.16; "subject:' ": 0.16; 'cc:addr:python- list': 0.16; 'pm,': 0.16; 'convert': 0.19; '(most': 0.21; 'cc:2**0': 0.21; 'cc:no real name:2**0': 0.22; 'header:In-Reply- To:1': 0.22; 'literal': 0.23; 'invalid': 0.25; 'traceback': 0.25; 'function': 0.26; 'thu,': 0.28; 'message-id:@mail.gmail.com': 0.28; 'cc:addr:python.org': 0.30; 'thanks': 0.31; 'does': 0.32; 'received:209.85.160': 0.34; 'there': 0.34; 'last):': 0.35; 'anything': 0.37; 'but': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.38; 'received:209': 0.40; 'jay': 0.84; 'leo': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=F37mjrL3HET7BY8ROQ9bIKmd3qLaryiQ09TgeTppCXg=; b=jwuEhtDOA8WBI6J0ubpMclZAKX9GMN2qrfv9uhwg0o8mBkEJTonJKz5HsWNkvbTo+h +9k3TuHgQogJo8tprQpM2oFF9bf1FKXtP2gftKYrw0nUTxi5wjGbyQFtd3iKyVKYQEah bq57amsQrhhYqa3rMdwltynaZQ69ZzMwhfRDg= MIME-Version: 1.0 In-Reply-To: References: Date: Thu, 21 Jul 2011 17:47:50 +0800 Subject: Re: Convert '165.0' to int From: Leo Jay To: Frank Millman Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1311241673 news.xs4all.nl 23875 [2001:888:2000:d::a6]:44306 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:10013 On Thu, Jul 21, 2011 at 5:31 PM, Frank Millman wrote: > > Hi all > > I want to convert '165.0' to an integer. > > The obvious method does not work - > >>>> x =3D '165.0' >>>> int(x) > > Traceback (most recent call last): > =C2=A0File "", line 1, in > ValueError: invalid literal for int() with base 10: '165.0' > > If I convert to a float first, it does work - > >>>> int(float(x)) > > 165 >>>> > > Is there a short cut, or must I do this every time (I have lots of them!)= ? I know I can write a function to do this, but is there anything built-in= ? > > Thanks > > Frank Millman > How about int(x[:-2])? -- Best Regards, Leo Jay