from datetime import causes error with today() function

Post any questions, ideas, or topics related to Jython and Python scripting.
Post Reply
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

from datetime import causes error with today() function

Post by joleenf »

Hi,

When I add the following import statement to my jython library (outside of a function):

from datetime import datetime, timedelta

today() starts returning the error

Screen Shot 2016-02-18 at 9.02.15 AM.png


Why is that? It seems okay to use the import within a function definition, so that is what I am going to do.

Joleen
User avatar
joleenf
Posts: 1123
Joined: Mon Jan 19, 2009 7:16 pm

Re: from datetime import causes error with today() function

Post by joleenf »

I did get an answer for why this might be happening.

The today() function is probably importing the datetime module as "import datetime" setting the reference to the module.

When I use from datetime import datetime, I am setting the reference to the datetime class and get the error. If I would use any of the following

import datetime
from datetime import datetime as dt
or from within a specific function "from datetime import datetime"

I do not have a problem with the today() function.

Joleen
Post Reply