Re: Get min and max dates

2016-12-08 Thread cantorp
Am Donnerstag, 8. Dezember 2016 14:47:31 UTC+1 schrieb DFS:
> On 12/8/2016 12:16 AM, Steven D'Aprano wrote:
> > On Thursday 08 December 2016 03:15, DFS wrote:
> >
> >> dts=  ['10-Mar-1998',
> >> '20-Aug-1997',
> >> '06-Sep-2009',
> >> '23-Jan-2010',
> >> '12-Feb-2010',
> >> '05-Nov-2010',
> >> '03-Sep-2009',
> >> '07-Nov-2014',
> >> '08-Mar-2013']
> >>
> >> Of course, the naive:
> >> min(dates) = '03-Sep-2009'
> >> max(dates) = '23-Jan-2010'
> >> is wrong.
> >>
> >> Not wanting to use any date parsing libraries, I came up with:
> > 
> >
> > That's where you have gone wrong. By not using a date parsing library which
> > works and has been tested, you have to write your own dodgy and possibly 
> > buggy
> > parsing routine yourself.
> >
> > Why reinvent the wheel?
> 
> 
> Because the "wheel" is a pain in the ass.
> 

Why? And why do you use this wording?

> --
> import time
> dts=['10-Mar-1908','20-Aug-1937','06-Sep-1969','23-Jan-1952']
> def date_to_seconds(string):
>  return time.mktime(time.strptime(string, '%d-%b-%Y'))
> print min(dts, key=date_to_seconds)
> --
> 
> OverflowError: mktime argument out of range
> 
> 

(snip)

> 
> I like that flexibility, but mktime is apparently useless for dates 
> prior to 'the epoch'.

With a little more experience in Python programming you should have discovered 
that time.mktime is not even required to do your calculations.

Please remove time.mktime from the function date_to_seconds and rename the 
function to date_to_timestruct.

-- Paolo
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: CSV to matrix array

2013-04-13 Thread cantorp
Dear Ana,

your example data could be transformed into a matrix with

>>>import csv
>>>rows = csv.reader(open("your_data_file.csv"), delimiter=" ")
>>>array = [row for row in rows]
>>>array[0][3]
4

HTH
Paolo

Am Freitag, 12. April 2013 19:29:05 UTC+2 schrieb Ana DionĂ­sio:
> That only puts the data in one column, I wanted to separate it. 
> 
> 
> 
> For example:
> 
> data in csv file:
> 
> 
> 
> 1 2 3 4 5
> 
> 7 8 9 10 11
> 
> a b c d e
> 
> 
> 
> I wanted an array where I could pick an element in each position. In the case 
> above if I did print array[0][3] it would pick 4

-- 
http://mail.python.org/mailman/listinfo/python-list