[Tutor] date problems

Alex Clark aclark at aclark.net
Thu Apr 29 01:59:08 CEST 2010


On 2010-04-28, Eric Meigs <thepond at hughes.net> wrote:
> This is a multi-part message in MIME format.
> --===============0277013919==
> Content-Type: multipart/alternative;
> 	boundary="------------060806000801070600050409"
>
> This is a multi-part message in MIME format.
> --------------060806000801070600050409
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> Content-Transfer-Encoding: 7bit
>
> I want to create a program to tell me when I am supposed to do things.
> I have a text file with dates like  4-4-2010' as well as other data. I 
> want to read in this date into my code and then compare it with 
> 'date.today()'
> example 'if /variable/ >= today:'
> I don't see how to read in a string and get it into a format for comparison.

So you have two questions here, one "how to read in a string" and two "get it 
into a format for comparison"?

It seems to me you could do something like this:

    from datetime import datetime

    input = open('dates.txt','rb')
    list = input.read()
    dates = list.split()[0] # chars before the first whitespace 
    items = list.split()[-1] # everything after the first whitespace

    if datetime.now().strftime('%m-%d-%Y') == dates:
        print 'Do %s today!' % items

(from http://github.com/aclark4life/Python-Tutor/blob/master/eric-meigs.py)

> I can do all of the other code.
>
> Eric
>
> --------------060806000801070600050409
> Content-Type: text/html; charset=ISO-8859-1
> Content-Transfer-Encoding: 7bit
>
><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
><html>
><head>
>
><meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
></head>
><body bgcolor="#ffffff" text="#000000">
><font size="-1"><font face="Arial">I want to create a program to tell
> me when I am supposed to do things.<br>
> I have a text file with dates like&nbsp; 4-4-2010' as well as other data. I
> want to read in this date into my code and then compare it with
> 'date.today()' <br>
> example 'if <i>variable</i> &gt;= today:' <br>
> I don't see how to read in a string and get it into a format for
> comparison.<br>
><br>
> I can do all of the other code.<br>
><br>
> Eric<br>
></font></font>
></body>
></html>
>
> --------------060806000801070600050409--
>
> --===============0277013919==
> Content-Type: text/plain; charset="us-ascii"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
> --===============0277013919==--
>


-- 
Alex Clark · http://aclark.net
Author of Plone 3.3 Site Administration · http://aclark.net/plone-site-admin



More information about the Tutor mailing list