[Tutor] Help for Python Beginner with extracting and manipulating data from thousands of ASCII files

Cecilia Chavana-Bryant cecilia.chavana at gmail.com
Wed Oct 3 11:16:19 CEST 2012


Got it, many thanks for your help.

On Tue, Oct 2, 2012 at 7:59 PM, Oscar Benjamin
<oscar.j.benjamin at gmail.com>wrote:

> Hi Cecilia, I'm sending this again as the first message was sent only
> to you (I hadn't realised that your own message was sent only to me as
> well). If you want to reply please reply-all to this message.
>
> On 1 October 2012 17:42, Cecilia Chavana-Bryant
> <cecilia.chavana at gmail.com> wrote:
> > On Mon, Oct 1, 2012 at 11:02 AM, Oscar Benjamin <
> oscar.j.benjamin at gmail.com>
> > wrote:
> >>
> >> On Sep 30, 2012 11:10 PM, "Cecilia Chavana-Bryant"
> >> <cecilia.chavana at gmail.com> wrote:
> >> >
> >> > fileDate = data[6][16:26] # location of the creation date on the data
> >> > files
> >>
> >> What format does fileDate have? I guess it's a string of text from the
> file. If
> >> you can convert it to a datetime (or date) object it will be easy to
> >> compare with the dates as required for your calibration file. Can you
> >> show us how it looks e.g.
> >>
> >> '12-Nov-2012'
> >> or
> >> '12/11/12'
> >> or something else?
> >
> >
> > Date is in the following format: dd/mm/yyyy
>
> The standard way to work with dates is to turn the date strings into
> Python datetime objects. You can read about those here:
> http://docs.python.org/library/datetime.html
>
> datetime objects can be create directly:
>
>     >>> from datetime import datetime
>     >>> start_date = datetime(year=2012, month=11, day=3)
>     >>> print start_date
>     2012-11-03 00:00:00
>
> You can also create them from a string:
>
>     >>> datestring = '10/11/2012'
>     >>> experiment_date = datetime.strptime(datestring, '%d/%m/%Y')
>     >>> print experiment_date
>     2012-11-10 00:00:00
>
> Once you have two datetime objects you can compare them directly:
>
>     >>> experiment_date > start_date
>     True
>     >>> print experiment_date - start_date
>     7 days, 0:00:00
>
> Using this you can check whether the date from the data file is in
> between the start and end dates for each of the calibration files and
> then choose which calibration file to use.
>
>
> Oscar
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121003/b01cf0ef/attachment-0001.html>


More information about the Tutor mailing list