Using Python for date calculations

2014-11-21 Thread Steve Hayes
I've finally found a use for Python. When, in the course of my genealogy research, I look at census or burial records, I often want to work out a person's date of birth from their age. It's a simple matter of mental arithmetic, but I sometimes get it wrong, and mislead myself. There are

Re: Using Python for date calculations

2014-11-21 Thread Chris Angelico
On Fri, Nov 21, 2014 at 7:35 PM, Steve Hayes hayes...@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

Re: Using Python for date calculations

2014-11-21 Thread Gary Herron
On 11/21/2014 12:35 AM, Steve Hayes wrote: I've finally found a use for Python. When, in the course of my genealogy research, I look at census or burial records, I often want to work out a person's date of birth from their age. It's a simple matter of mental arithmetic, but I sometimes get it

Re: Using Python for date calculations

2014-11-21 Thread Steve Hayes
On Fri, 21 Nov 2014 19:40:22 +1100, Chris Angelico ros...@gmail.com wrote: On Fri, Nov 21, 2014 at 7:35 PM, Steve Hayes hayes...@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

Re: Using Python for date calculations

2014-11-21 Thread Chris Angelico
On Fri, Nov 21, 2014 at 9:15 PM, Steve Hayes hayes...@telkomsa.net wrote: On Fri, 21 Nov 2014 19:40:22 +1100, Chris Angelico ros...@gmail.com wrote: On Fri, Nov 21, 2014 at 7:35 PM, Steve Hayes hayes...@telkomsa.net wrote: This Python script does it for me. year = input(Year: ) age =

Re: Using Python for date calculations

2014-11-21 Thread Mark Lawrence
On 21/11/2014 08:50, Gary Herron wrote: On 11/21/2014 12:35 AM, Steve Hayes wrote: I've finally found a use for Python. When, in the course of my genealogy research, I look at census or burial records, I often want to work out a person's date of birth from their age. It's a simple matter of

Re: Using Python for date calculations

2014-11-21 Thread Chris Angelico
On Fri, Nov 21, 2014 at 9:20 PM, Mark Lawrence breamore...@yahoo.co.uk wrote: As we're now firmly heading into the Python 3 era would people please be kind enough to use the Python 3 links. I know it's only a single character change but it's the principle to me. TIA. The OP was clearly using

Re: Using Python for date calculations

2014-11-21 Thread alister
On Fri, 21 Nov 2014 12:15:03 +0200, Steve Hayes wrote: On Fri, 21 Nov 2014 19:40:22 +1100, Chris Angelico ros...@gmail.com wrote: On Fri, Nov 21, 2014 at 7:35 PM, Steve Hayes hayes...@telkomsa.net wrote: This Python script does it for me. year = input(Year: ) age = input(Age: ) born =

Re: Using Python for date calculations

2014-11-21 Thread alister
On Fri, 21 Nov 2014 10:20:06 +, Mark Lawrence wrote: On 21/11/2014 08:50, Gary Herron wrote: On 11/21/2014 12:35 AM, Steve Hayes wrote: I've finally found a use for Python. When, in the course of my genealogy research, I look at census or burial records, I often want to work out a

Re: Using Python for date calculations

2014-11-21 Thread Chris Angelico
On Fri, Nov 21, 2014 at 9:33 PM, alister alister.nospam.w...@ntlworld.com wrote: the data entered by the user is processed as if it was python code, this means the user could enter a command (or sequence of commands) that cause serious problems to you computer including but not limited to:-

Re: Using Python for date calculations

2014-11-21 Thread random832
On Fri, Nov 21, 2014, at 05:33, alister wrote: the problem with input is code-injection which is very similar to sql injection (httpd://xkcd.com/327). the data entered by the user is processed as if it was python code, this means the user could enter a command (or sequence of commands)

Re: Using Python for date calculations

2014-11-21 Thread random832
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

Re: Using Python for date calculations

2014-11-21 Thread Chris Angelico
On Sat, Nov 22, 2014 at 12:58 AM, random...@fastmail.us wrote: 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.

Re: Using Python for date calculations

2014-11-21 Thread alister
On Fri, 21 Nov 2014 08:54:23 -0500, random832 wrote: On Fri, Nov 21, 2014, at 05:33, alister wrote: the problem with input is code-injection which is very similar to sql injection (httpd://xkcd.com/327). the data entered by the user is processed as if it was python code, this means the

Re: Using Python for date calculations

2014-11-21 Thread Steven D'Aprano
random...@fastmail.us wrote: 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). Not

Re: Using Python for date calculations

2014-11-21 Thread Ned Batchelder
On 11/21/14 9:55 AM, Steven D'Aprano wrote: - Use your OS facilities to run that process in a chroot jail. If you are interested, this is the facility that edX uses to run untrusted Python code on the servers: https://github.com/edx/codejail -- Ned Batchelder, http://nedbatchelder.com --

Re: Using Python for date calculations

2014-11-21 Thread Steve Hayes
On Fri, 21 Nov 2014 10:20:06 +, Mark Lawrence breamore...@yahoo.co.uk wrote: On 21/11/2014 08:50, Gary Herron wrote: On 11/21/2014 12:35 AM, Steve Hayes wrote: I've finally found a use for Python. When, in the course of my genealogy research, I look at census or burial records, I often

Re: Using Python for date calculations

2014-11-21 Thread Mark Lawrence
On 21/11/2014 15:50, Steve Hayes wrote: On Fri, 21 Nov 2014 10:20:06 +, Mark Lawrence breamore...@yahoo.co.uk As I'm using Python 2 and I asked the question, I'm grateful that the answer was given in my dialect. Luddite :) -- My fellow Pythonistas, ask not what our language can do for

Re: Using Python for date calculations

2014-11-21 Thread duncan smith
On 21/11/14 08:35, Steve Hayes wrote: I've finally found a use for Python. When, in the course of my genealogy research, I look at census or burial records, I often want to work out a person's date of birth from their age. It's a simple matter of mental arithmetic, but I sometimes get it

Re: Using Python for date calculations

2014-11-21 Thread Steve Hayes
On Fri, 21 Nov 2014 17:03:12 +, duncan smith buzzard@invalid.invalid wrote: On 21/11/14 08:35, Steve Hayes wrote: I've finally found a use for Python. When, in the course of my genealogy research, I look at census or burial records, I often want to work out a person's date of birth from

Re: Using Python for date calculations

2014-11-21 Thread Paul Blair
On 22-Nov-2014 6:35 am, Dennis Lee Bieber wrote: On Fri, 21 Nov 2014 10:35:19 +0200, Steve Hayes hayes...@telkomsa.net declaimed the following: This Python script does it for me. year = input(Year: ) age = input(Age: ) born = year-age print 'Year of birth:', born It's so simple, so

Re: Using Python for date calculations

2014-11-21 Thread Steve Hayes
On Fri, 21 Nov 2014 14:50:36 -0500, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Fri, 21 Nov 2014 12:15:03 +0200, Steve Hayes hayes...@telkomsa.net declaimed the following: On Fri, 21 Nov 2014 19:40:22 +1100, Chris Angelico ros...@gmail.com wrote: On Fri, Nov 21, 2014 at 7:35 PM, Steve

Re: Using Python for date calculations

2014-11-21 Thread Chris Angelico
On Sat, Nov 22, 2014 at 4:07 PM, Steve Hayes hayes...@telkomsa.net wrote: On Fri, 21 Nov 2014 14:50:36 -0500, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Fri, 21 Nov 2014 12:15:03 +0200, Steve Hayes hayes...@telkomsa.net declaimed the following: On Fri, 21 Nov 2014 19:40:22 +1100, Chris

Re: Using Python for date calculations

2014-11-21 Thread Steve Hayes
On Sat, 22 Nov 2014 06:51:15 +1100, Paul Blair p.bl...@internode.on.net wrote: On 22-Nov-2014 6:35 am, Dennis Lee Bieber wrote: On Fri, 21 Nov 2014 10:35:19 +0200, Steve Hayes hayes...@telkomsa.net declaimed the following: This Python script does it for me. year = input(Year: ) age =

Re: Using Python for date calculations

2014-11-21 Thread Steve Hayes
On Fri, 21 Nov 2014 15:07:39 -0500, Denis Beauregard denis.b-at-francogene.com@fr.invalid wrote: On Fri, 21 Nov 2014 14:35:14 -0500, Dennis Lee Bieber bieber.geneal...@earthlink.net wrote in soc.genealogy.computing: On Fri, 21 Nov 2014 10:35:19 +0200, Steve Hayes hayes...@telkomsa.net declaimed