Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'operator': 0.03; 'irc': 0.05; 'subject:Python': 0.06; '21,': 0.07; 'function,': 0.09; 'received:internal': 0.09; 'to)': 0.09; 'typed': 0.09; 'accepting': 0.14; '"enter': 0.16; '(written': 0.16; 'calculator': 0.16; 'limiting': 0.16; 'literal.': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:messagingengine.com': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'code': 0.31; 'pickle': 0.31; '(i.e.': 0.33; 'fri,': 0.33; 'sense': 0.34; 'maybe': 0.34; 'received:66': 0.35; 'classes': 0.35; 'but': 0.35; 'there': 0.35; 'received:10': 0.37; 'clear': 0.37; 'sometimes': 0.38; 'nov': 0.38; 'to:addr:python- list': 0.38; 'anything': 0.39; 'channel': 0.39; 'to:addr:python.org': 0.39; 'removing': 0.60; 'from:no real name:2**0': 0.61; 'strictly': 0.61; "you're": 0.61; 'times': 0.62; 'header:Message-Id:1': 0.63; 'act': 0.63; 'number:': 0.66; '2014,': 0.84; 'fine...': 0.84; 'subject:Using': 0.84 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.us; h= message-id:x-sasl-enc:from:to:mime-version :content-transfer-encoding:content-type:in-reply-to:references :subject:date; s=mesmtp; bh=CbjxZHITOelTq3I+HRoVJUe4mcU=; b=slvA JtzRbevKvvR0qUBSMLyXlGRZktII/r3nm3ML3+Te/3o9lmcRzf0VT9IKWOlpnlwI jfFZgTSxiuwWuYjO7Vskw2NQJEUiWpdvJtHVPpnmdY+WuhnALn6Kz3J/iUC5Qfn+ 9yBa9qNazcAIMUFoTCVqKlMvGjhJF2bM/NRzgu0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:x-sasl-enc:from:to :mime-version:content-transfer-encoding:content-type:in-reply-to :references:subject:date; s=smtpout; bh=CbjxZHITOelTq3I+HRoVJUe4 mcU=; b=MazARPQQSah6HQCFgFbsT2AROdmx6C8Gg8SBy+ZMrBKxkUKv9yeDWl0Z E9LYP8CMVEBr4Z1KP64h8PO+MTkRs3CmfnQfEr+z7RVaxGB4tXkL7GuUqgzc56Eu p/aiLbWrhzmHv7Y2Xyh7Q+OZj1vIXzGbKP58Yt0M2vEboJ6SnBk= X-Sasl-Enc: qB044gWqmy93K0qKbPh1TUYZ7mYpS7yAk0J+m9vrcwBV 1416578293 From: random832@fastmail.us To: python-list@python.org MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain X-Mailer: MessagingEngine.com Webmail Interface - ajax-a419c8a0 In-Reply-To: References: <0yEbw.852077$KL.733426@fx19.am4> Subject: Re: Using Python for date calculations Date: Fri, 21 Nov 2014 08:58:13 -0500 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: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416578295 news.xs4all.nl 2845 [2001:888:2000:d::a6]:50397 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81204 On Fri, Nov 21, 2014, at 05:47, Chris Angelico wrote: > Now, maybe you want it to eval. There are times when I conceptually > want "enter an integer", but it makes good sense to be able to type > "1+2" and have it act as if I typed "3". That's fine... but if you > want eval, write eval into your code. Be explicit: > eval(raw_input("Enter a number: ")) makes it very clear that you're > accepting code at the console. Out of curiosity, is there a way to use eval "safely" (i.e. strictly limiting what it has access to) across a privilege boundary? This also comes up for pickle and other serialization formats that can store arbitrary classes (i.e. call arbitrary constructors). I remember an IRC channel I sometimes go in has a chatbot (written in perl) which has a calculator function, it goes with the low-tech solution of removing via regex anything that isn't an operator or a number literal.