Note that there are some explanatory texts on larger screens.

plurals
  1. POHandling the different results from parsedatetime
    text
    copied!<p>I'm trying to learn python after spending the last 15 or so years working only in Perl and only occasionally.</p> <p>I can't understand how to handle the two different kinds of results from the parse method of Calendar.parse() from parsedatetime</p> <p>Given this script:</p> <pre><code>#!/usr/bin/python import parsedatetime.parsedatetime as pdt import parsedatetime.parsedatetime_consts as pdc import sys import os # create an instance of Constants class so we can override some of the defaults c = pdc.Constants() # create an instance of the Calendar class and pass in our Constants # object instead of letting it create a default p = pdt.Calendar(c) while True: reply = raw_input('Enter text:') if reply == 'stop': break else: result = p.parse(reply) print result print </code></pre> <p>And this sample run:</p> <blockquote> <p>Enter text:tomorrow<br> (time.struct_time(tm_year=2009, tm_mon=11, tm_mday=28, tm_hour=9, tm_min=0, tm_sec=0, tm_wday=5, tm_yday=332, tm_isdst=-1), 1) </p> <p>Enter text:11/28<br> ((2009, 11, 28, 14, 42, 55, 4, 331, 0), 1) </p> </blockquote> <p>I can't figure out how to get the output such that I can consisently use result like so:</p> <pre><code>print result[0].tm_mon, result[0].tm_mday </code></pre> <p>That won't work in the case where the input is "11/28" because the output is just a tuple and not a struct_time. </p> <p>Probably a simple thing.. but not for this newbie. From my perspective the output of Calendar.parse() is unpredictable and hard to use. Any help appreciated. Tia.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload