[Tutor] How to unpack python-dateutil-2.0.tar.gz

eryksun eryksun at gmail.com
Fri Oct 19 06:41:49 CEST 2012

On Thu, Oct 18, 2012 at 11:55 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> Have you tried running `date` at the Windows command.com (or cmd.exe,
> or something, I never remember which)? What does it print?
> My guess is that it probably prints something like:
> "Command not found"
> which clearly cannot be parsed as a date.

Windows has separate date and time commands ('date /t' and 'time /t'),
but it's simpler to use 'echo %time% %date%' in the shell.

Also, the demo script isn't for Python 3.x. It uses "print" as a
statement and the "commands" module, which is deprecated in 2.x and
removed from 3.x.

Try this instead:

    import sys
    import os
    import subprocess
    from dateutil.relativedelta import *
    from dateutil.easter import *
    from dateutil.rrule import *
    from dateutil.parser import *
    from datetime import *

    if sys.platform == 'win32':
        cmd = 'echo %time% %date%'
        shell = True
        cmd = 'date'
        shell = False
    datestr = subprocess.check_output(cmd, shell=shell).decode()

    now = parse(datestr)
    today = now.date()
    year = rrule(YEARLY,bymonth=8,bymonthday=13,byweekday=FR)[0].year
    rdelta = relativedelta(easter(year), today)
    print("Today is:", today)
    print("Year with next Aug 13th on a Friday is:", year)
    print("How far is the Easter of that year:", rdelta)
    print("And the Easter of that year is:", today+rdelta)

More information about the Tutor mailing list