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


Groups > comp.lang.python > #46752

Re: Issue converting to string to integer.

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'tries': 0.07; 'dan': 0.09; 'input,': 0.09; 'literal': 0.09; 'okay': 0.09; 'prevents': 0.09; 'subject:string': 0.09; 'valueerror:': 0.09; 'python': 0.11; '"if"': 0.16; "'0'": 0.16; '23,': 0.16; 'fails.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.18; 'subject:Issue': 0.19; 'input': 0.22; 'error': 0.23; 'mon,': 0.24; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; '-0700,': 0.31; 'file': 0.32; '(most': 0.33; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'skip:" 50': 0.36; 'two': 0.37; 'being': 0.38; 'version,': 0.38; 'to:addr :python-list': 0.38; 'rather': 0.38; 'recent': 0.39; 'though,': 0.39; 'to:addr:python.org': 0.39; 'blank': 0.60; 'tell': 0.60; 'conversion': 0.61; "you're": 0.61; 'first': 0.61; 'happen': 0.63; 'different': 0.65; 'between': 0.67; 'invalid': 0.68; 'line,': 0.68; '10:': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=1yvIefjAfqBnfhvdCmNWQJDs9leFBtqwuDwPYfDGM+8=; b=JSEODq0QVDEoMFOb+3zFJLiWskKhhN5PWjesxqiT1hemVB+v3WUI07KKqYUBpwKIX1 Luwy5pccy/+rOhb3zxXKvQ2E3e5WcfJYS37Es+PViryWajYC0yZ/2y/smI/2wcFNAHyQ TyZI82hV/4qRD1E1tmqGfP+eiXrVbhgd4aqacjzlvi1QS+D3vJzoaO97Z2gf58/DGLWQ E/uev3oJloHqkrM6QGQszv9mdTF/XKHyt2VtpA2TXTKMnL66COouYmlADsorWtYEosKG +HNxqhHcNPaImO9lkcECIlgB1CorYi92ZOR3hWqQaMfqS2S2MM826zFLeok11NG+xGAF Og/A==
MIME-Version 1.0
X-Received by 10.220.106.74 with SMTP id w10mr16263701vco.32.1370225288012; Sun, 02 Jun 2013 19:08:08 -0700 (PDT)
In-Reply-To <DFSqt.45780$CG1.40950@newsfe21.iad>
References <55c2eb06-7b9f-480f-8668-5e19e236799f@googlegroups.com> <DFSqt.45780$CG1.40950@newsfe21.iad>
Date Mon, 3 Jun 2013 12:08:07 +1000
Subject Re: Issue converting to string to integer.
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2574.1370225290.3114.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1370225290 news.xs4all.nl 15896 [2001:888:2000:d::a6]:58282
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:46752

Show key headers only | View raw


On Mon, Jun 3, 2013 at 11:52 AM, Dan Sommers <dan@tombstonezero.net> wrote:
> On Sun, 02 Jun 2013 18:12:33 -0700, Fdama wrote:
>
>> I combined the int conversion and the input on the same line, rather
>> than to have two different statements. But got an error message:
>
>> Traceback (most recent call last):
>>   File "C:\Users\Faisal\Documents\python\pizza_slicer.py", line 23, in <module>
>>     start=int(input("\nStart: "))
>> ValueError: invalid literal for int() with base 10: ''
>>
>> Could someone tell me why I got this error message?
>
> The difference is what used to happen in between the input and the
> conversion.  In the first version, the "if" statement prevents the
> conversion from happening when there is no input.  In the second
> version, though, python tries to do the conversion with no input, and
> fails.

You could combine them in, as long as you're okay with blank input and
input of '0' being folded to the same:

start = int(input("\nStart: ") or 0)

ChrisA

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


Thread

Issue converting to string to integer. Fdama <fsdama@gmail.com> - 2013-06-02 18:12 -0700
  Re: Issue converting to string to integer. Dan Stromberg <drsalists@gmail.com> - 2013-06-02 18:44 -0700
  Re: Issue converting to string to integer. Dan Sommers <dan@tombstonezero.net> - 2013-06-03 01:52 +0000
    Re: Issue converting to string to integer. Chris Angelico <rosuav@gmail.com> - 2013-06-03 12:08 +1000
  Re: Issue converting to string to integer. alex23 <wuwei23@gmail.com> - 2013-06-02 19:02 -0700

csiph-web