Jump to content

Ironpython syntax error issue


Anthony stark

Recommended Posts

Hi Guys have the follow lince of code below:

import datetime

todayDate = Document.Properties['CurrentDateTimeProperty']

if todayDate.day is 1:

myFunction()

else:

pass

The error im getting when i run this is: "AttributeError: 'DateTime' object has no attribute 'day'

when i try : if todayDate.day = 1: (instead of using "is"), i get this error: SyntaxError: unexpected token '='

How can i get the code to recognise the ['CurrentDateTimeProperty'] property

Thaanks in advance

Link to comment
Share on other sites

While the document property may be a datetime it does not have the method .day

 

You can wrap your document property in datetime.datetime() so that is has the .day method.

 

import datetime

todayDate = datetime.datetime(Document.Properties['CurrentDateTimeProperty'])

if todayDate.day == 1:

myfunc()

else:

pass

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...