time.strptime intolerant on weekday string length?

Discussion in 'Python' started by Robert, Sep 13, 2005.

  1. Robert

    Robert Guest

    A certain DAV server reports a time stamp as "Tues, 30 Aug 2005 20:48:31"
    ( but not "Tue, ..." as usual)

    This produces the error below.

    >>> time.strptime("Tue, 30 Aug 2005 20:48:31","%a, %d %b %Y %H:%M:%S")

    (2005, 8, 30, 20, 48, 31, 1, 242, -1)
    >>> time.strptime("Tues, 30 Aug 2005 20:48:31","%a, %d %b %Y %H:%M:%S")

    Traceback (most recent call last):
    File "<interactive input>", line 1, in ?
    File "C:\Python23\lib\_strptime.py", line 425, in strptime
    raise ValueError("time data did not match format: data=%s fmt=%s" %
    ValueError: time data did not match format: data=Tues, 30 Aug 2005 20:48:31
    fmt=%a, %d %b %Y %H:%M:%S
    >>>



    I also don't see how to alter the pattern for strptime to be tolerante for
    more long weekday strings?
    Any ideas?
    Shouldn't it be possible to insert real regexp-like stuff in the pattern?

    Robert
    Robert, Sep 13, 2005
    #1
    1. Advertising

  2. Robert wrote:

    >A certain DAV server reports a time stamp as "Tues, 30 Aug 2005 20:48:31"
    > ( but not "Tue, ..." as usual)


    > I also don't see how to alter the pattern for strptime to be tolerante for
    > more long weekday strings?
    > Any ideas?


    why bother parsing the day name at all? (just split the string at the first
    command and use strptime on the rest)

    > Shouldn't it be possible to insert real regexp-like stuff in the pattern?


    if you need an RE, use an RE. no need to use strptime if you don't what
    that behaviour (to convert the RE result to a time value, use time.mktime,
    calender.timegm, or the datetime module, depending on what you want)

    </F>
    Fredrik Lundh, Sep 13, 2005
    #2
    1. Advertising

  3. > why bother parsing the day name at all? (just split the string at the first
    > command and use strptime on the rest)


    msg = msg.replace("command", "comma")

    </F>
    Fredrik Lundh, Sep 13, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chumley the Walrus

    Parsing a weekday from a date object

    Chumley the Walrus, Aug 11, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,232
    Ken Cox [Microsoft MVP]
    Aug 11, 2004
  2. Chumley the Walrus

    Weekday date object function in datalist

    Chumley the Walrus, Aug 12, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    374
    Chumley the Walrus
    Aug 12, 2004
  3. kongkolvyu
    Replies:
    4
    Views:
    478
    Old Wolf
    Jan 4, 2006
  4. Greg Krohn
    Replies:
    1
    Views:
    934
    Denis Kasak
    Feb 17, 2009
  5. Jim

    intolerant HTML parser

    Jim, Feb 6, 2010, in forum: Python
    Replies:
    12
    Views:
    468
Loading...

Share This Page