Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!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.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'advocate': 0.07; 'wednesday,': 0.07; '22,': 0.09; 'type,': 0.09; 'subject:question': 0.10; '18:': 0.16; 'fabio': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'integer,': 0.16; 'sys.exit(0)': 0.16; 'using,': 0.16; 'world!': 0.16; 'wrote:': 0.18; 'wed,': 0.18; '>>>': 0.22; 'certainly': 0.24; 'integer': 0.24; 'script.': 0.24; 'this:': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'kevin': 0.30; 'message- id:@mail.gmail.com': 0.30; 'url:python': 0.33; 'received:209.85': 0.35; 'received:209.85.220': 0.35; 'convert': 0.35; 'no,': 0.35; 'received:google.com': 0.35; 'url:org': 0.36; 'received:209': 0.37; 'url:library': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'read': 0.60; '(that': 0.65; 'age': 0.80; 'goblin': 0.84; 'hammer': 0.84; 'directly.': 0.95; '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=R8uC2Wid18kZX4Sj47+MqPxrh5DR1lD8wiKM9ecQdbc=; b=TPo/z1VS9w/7K/8GkQ13qp795NnVqomVbWikj5gXf0TuZZV0sNQYbUznSFT5NH63AT f1LXPJmuCbnb121gpbfpuvsNx3lDU28vG3AYGoX8Ew5yFu5kuvISQadVGQ0Q0t/tlkGJ rhaPvD7bh+APsfgDSAlGGyJ3M9kLuB3B2KCEbLvQKFpnoaLLIJfskil17J5LGZGn+sud 5OiM7c7YsJtYW/RwFFtcAdUBd84Mwjt0EBcPIey3L7JC+Kt+K9bgcXrsP2anVDif4qcu dxuOXeMRdpAF7ZlJX3YS+FPw6stWEV8gA1YgG5qCASMe8+AXv4+xR/p6T3xKhOX9w4Dj E8kQ== MIME-Version: 1.0 X-Received: by 10.220.106.74 with SMTP id w10mr2363735vco.32.1369207146151; Wed, 22 May 2013 00:19:06 -0700 (PDT) In-Reply-To: References: <534d7800-14c1-430b-85fb-dd703c2acc4d@googlegroups.com> Date: Wed, 22 May 2013 17:19:06 +1000 Subject: Re: Newbie question about evaluating raw_input() responses From: Chris Angelico 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369207155 news.xs4all.nl 15915 [2001:888:2000:d::a6]:46852 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45716 On Wed, May 22, 2013 at 4:52 PM, Kevin Xi wrote: > On Wednesday, May 22, 2013 2:23:15 PM UTC+8, C. N. Desrosiers wrote: >> age=raw_input('Enter your age: ') >> if age > 18: > > You can either use `raw_input` to read data and convert it to right type, or use `input` to get an integer directly. Read this: http://docs.python.org/2/library/functions.html#raw_input > http://docs.python.org/2/library/functions.html#input No! No, please do NOT use input()! It does not return an integer; it *evaluates* (that is, executes) the input. >>> input('Enter your age: ') Enter your age: 18 18 >>> input('Enter your age: ') Enter your age: 1+2+4+5+6 18 >>> input('Enter your age: ') Enter your age: sys.stdout.write("Hello, world!\n") or 18 Hello, world! 18 >>> input('Enter your age: ') Enter your age: sys.exit(0) This is almost certainly NOT what you want to have in your script. If you want an integer, just pass it through int() as Fabio suggested. Please do not use, or advocate using, this steam-powered Izzet goblin hammer for cracking walnuts. ChrisA