Basic-ish Python Question - May be related to framework.bundle

I’m having a bit of trouble with a plugin i’m working on. I’m utilizing some of the timezone specific functions that the DateUtil python module provides. The only issue i’m having is that i can’t seem to figure out how exactly to import the module so i can utilize some its classes/functions/methods.



For example, the following code works just fine when i run it via command line on my computer. (local python install)


<br />
import dateutil.parser, dateutil.tz, datetime<br />
<br />
current_datetime = datetime.datetime.now(dateutil.tz.tzutc())<br />
<br />
datetime_fromapi = "2013-03-14T14:15:23-07:00" #I'm getting this via JSON, but this is just an example<br />
<br />
session_expires = dateutil.parser.parse(datetime_fromapi)<br />
<br />
if current_datetime > session_expires:<br />
    print "Session Expired"<br />
else:<br />
    print "Session Valid"<br />




However when i run it via Plex, i get this weird cryptic error that makes me think i'm not importing the module correctly.



I can work around this bug by adding the following code:


dateutilparser = dateutil.parser()



And then changing my references to dateutil.parser.parse() to dateutilparser.parse().

Furthermore, i don't get any errors when it comes to calling dateutil.tz.tzutc(). I would think that it would have the same limitation as dateutil.parser.parse(). Very very weird. (or not...)

I'd just like to know what i'm doing wrong. Am i not importing the modules correctly? Should i import them using the "from dateutil.parser import *"? I've read a lot of Python "best practices" that say the only way you should ever import modules is using "import" and that "from" is only to be used if absolutely necessary. Is this true?

Thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.