Calculating Year, Month and Day of Life

Terry Reedy tjreedy at udel.edu
Sat Jul 5 22:44:47 CEST 2003


> My problem is that localtime is a list of 9 integers while age is a
list
> of 3 integers. Is it possible to make localtime() only return the
first
> 3 integers?

No, but you can easily slice out what you want -- localtime()[0:3] -- 
or wrap it with a function that does the same -- def localymd():
return localtime[0:3].

> If so, how would I then do calculations on the two lists'
> individual parts? For example, how would I instruct localtime() to
> subtract the first integer from age's list from the first intger in
its
> own list (2003 - 1934)?

The mathematical approach is to convert both ymds to Julian days and
subtract to get number of days of life.  But since 'month' does not
have a fixed number of days, it is hard to convert back to get the
commonly expected answer for (y,m,d)s of life.  So you need to do the
subtraction the way it is commonly performed or at least the way you
want it to be   (The problem is to figure out what to do when you need
to 'borrow' a month in order to subtract days.)

> Also, I am new to python, but I like it a lot and have picked it up
squickly

Welcome.

Terry J. Reedy






More information about the Python-list mailing list