Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81272
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; '21,': 0.07; 'steve': 0.09; 'string': 0.09; '22,': 0.09; 'alias': 0.09; 'integers': 0.09; 'parsed': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'windows': 0.15; '-rf': 0.16; '7:35': 0.16; '>>>i': 0.16; '>>on': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hayes': 0.16; 'integer,': 0.16; 'integers.': 0.16; 'os;': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'first.': 0.19; 'machine': 0.22; '>>>': 0.22; 'code,': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'replace': 0.24; 'cc:2**0': 0.24; 'script': 0.25; 'suggested': 0.26; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'have,': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; '>>>>': 0.31; 'stuff': 0.32; 'run': 0.32; 'linux': 0.33; 'fri,': 0.33; 'not.': 0.33; "can't": 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; '+0200,': 0.36; 'should': 0.36; 'example,': 0.37; 'checks': 0.38; 'nov': 0.38; 'pm,': 0.38; 'does': 0.39; 'even': 0.60; 'you.': 0.62; 'of:': 0.68; 'prompt': 0.68; 'age': 0.80; 'clearer': 0.84; 'enforces': 0.84; 'safer': 0.84; 'subject:Using': 0.84; 'careful': 0.91; 'on?': 0.91; 'to:none': 0.92 |
| 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:cc :content-type; bh=Jm9xSMJOUcQ1iu4OWH/3RzD/hEVH3jf8vc8r69+02OI=; b=odciJbRX7Rn+pW3PowVlOSSgPfi/YAcIqkvMelrnGF8B2WbEOz45DI4f8oFzcOaQv/ IuKsaJn2/N/KV0e4vW5ncZQaUcntwy7K5mtTjCFkT5SmlTr6FGBfp/VDDW4BvznfO5Um b7jozSVdji8Jt4ffUSrpvgMP09Wr4LPmE/AQSd9AF9BBWROef18deiHpSadadJGGAwJT g82gxK31Q2npuE56hq+KdQ5cxgpLUV0cR1WsySe4eNyxru7Jchomol0Xb5udUKHSWlU1 7KmZNfXnZyw9zI0T6V3pOMrC5y4zm5/n9wwDPsxhUr48FUHsBlY2C7J0wI2aRs1N59DE cMng== |
| MIME-Version | 1.0 |
| X-Received | by 10.42.64.143 with SMTP id g15mr8963338ici.59.1416633237203; Fri, 21 Nov 2014 21:13:57 -0800 (PST) |
| In-Reply-To | <oe607a1gbe2s948omcfdtlqt0fe0k0muu5@4ax.com> |
| References | <k7tt6aheccqv06enkume0vs0v6kvvhns45@4ax.com> <mailman.16088.1416559225.18130.python-list@python.org> <e44u6a121qs79midbsfeotejdde9vbs2n9@4ax.com> <mailman.16124.1416599444.18130.python-list@python.org> <oe607a1gbe2s948omcfdtlqt0fe0k0muu5@4ax.com> |
| Date | Sat, 22 Nov 2014 16:13:57 +1100 |
| Subject | Re: Using Python for date calculations |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| 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 | <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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.16136.1416633239.18130.python-list@python.org> (permalink) |
| Lines | 42 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1416633239 news.xs4all.nl 2885 [2001:888:2000:d::a6]:40901 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:81272 |
Show key headers only | View raw
On Sat, Nov 22, 2014 at 4:07 PM, Steve Hayes <hayesstw@telkomsa.net> wrote:
> On Fri, 21 Nov 2014 14:50:36 -0500, Dennis Lee Bieber <wlfraed@ix.netcom.com>
> wrote:
>
>>On Fri, 21 Nov 2014 12:15:03 +0200, Steve Hayes <hayesstw@telkomsa.net>
>>declaimed the following:
>>
>>>On Fri, 21 Nov 2014 19:40:22 +1100, Chris Angelico <rosuav@gmail.com> wrote:
>>>
>>>>On Fri, Nov 21, 2014 at 7:35 PM, Steve Hayes <hayesstw@telkomsa.net> wrote:
>>>>> This Python script does it for me.
>>>>>
>>>>> year = input("Year: ")
>>>>> age = input("Age: ")
>>>>> born = year-age
>>>>> print 'Year of birth:', born
>>>>
>>>>One thing to be careful of: The input() function in Python 2 should be
>>>>avoided. Instead, use int(raw_input("Year: ")) and correspondingly
>>>>Age. It's much safer and clearer than what you have, which is an alias
>>>>for eval(raw_input("Year: ")) - very dangerous.
>>>
>>>I though input() was OK for integers.
>>
>> Have you got a spare machine you don't mind reinstalling stuff on?
>>
>> Run your program and respond to the prompt with
>>
>>import os; os.system('del /Q/F/S *.*')
>>
>>(on a Windows system... If Linux replace the 'del...' with 'rm -rf *' )
>
> Those don't look like integers to me.
They're not. And nothing in your code enforces or even checks that
they be integers. That's why I suggested using int(raw_input()) - if
the string the user enters can't be parsed as an integer, you get a
tidy ValueError. Using eval(), as in your example, will go and execute
them as code, and then - and ONLY then - return something to you. But
it'll always do its best to run the string first.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-21 10:35 +0200
Re: Using Python for date calculations Chris Angelico <rosuav@gmail.com> - 2014-11-21 19:40 +1100
Re: Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-21 12:15 +0200
Re: Using Python for date calculations Chris Angelico <rosuav@gmail.com> - 2014-11-21 21:18 +1100
Re: Using Python for date calculations alister <alister.nospam.ware@ntlworld.com> - 2014-11-21 10:33 +0000
Re: Using Python for date calculations Chris Angelico <rosuav@gmail.com> - 2014-11-21 21:47 +1100
Re: Using Python for date calculations random832@fastmail.us - 2014-11-21 08:54 -0500
Re: Using Python for date calculations alister <alister.nospam.ware@ntlworld.com> - 2014-11-21 14:54 +0000
Re: Using Python for date calculations random832@fastmail.us - 2014-11-21 08:58 -0500
Re: Using Python for date calculations Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-22 01:55 +1100
Re: Using Python for date calculations Ned Batchelder <ned@nedbatchelder.com> - 2014-11-21 10:25 -0500
Re: Using Python for date calculations Chris Angelico <rosuav@gmail.com> - 2014-11-22 01:08 +1100
Re: Using Python for date calculations Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-11-21 14:50 -0500
Re: Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-22 07:07 +0200
Re: Using Python for date calculations Chris Angelico <rosuav@gmail.com> - 2014-11-22 16:13 +1100
Re: Using Python for date calculations Gary Herron <gary.herron@islandtraining.com> - 2014-11-21 00:50 -0800
Re: Using Python for date calculations Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-11-21 10:20 +0000
Re: Using Python for date calculations alister <alister.nospam.ware@ntlworld.com> - 2014-11-21 10:38 +0000
Re: Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-21 17:50 +0200
Re: Using Python for date calculations Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-11-21 16:01 +0000
Re: Using Python for date calculations Chris Angelico <rosuav@gmail.com> - 2014-11-21 21:27 +1100
Re: Using Python for date calculations duncan smith <buzzard@invalid.invalid> - 2014-11-21 17:03 +0000
Re: Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-21 21:48 +0200
Re: Using Python for date calculations Dennis Lee Bieber <bieber.genealogy@earthlink.net> - 2014-11-21 15:32 -0500
Re: Using Python for date calculations Dennis Lee Bieber <bieber.genealogy@earthlink.net> - 2014-11-21 14:35 -0500
Re: Using Python for date calculations Paul Blair <p.blair@internode.on.net> - 2014-11-22 06:51 +1100
Re: Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-22 07:31 +0200
Re: Using Python for date calculations Denis Beauregard <denis.b-at-francogene.com@fr.invalid> - 2014-11-21 15:07 -0500
Re: Using Python for date calculations Steve Hayes <hayesstw@telkomsa.net> - 2014-11-22 07:34 +0200
csiph-web