AnsweredAssumed Answered

How to write a if conditional stored in a variable?

Question asked by vshah6 on Jul 10, 2017
Latest reply on Jul 10, 2017 by Dan_Patterson

I am currently writing a script where it's to automate generating reports for end of quarter reports. Part of the naming convention for the folders includes Q1, Q2, Q3, or Q4 based on which quarter it is for based on the date it is generated. So far, my code looks like this:

 

import arcpy
import datetime

date = datetime.date.today()

quarter = 'Q1' if '2017-01-01' =< str(date) =< '2017-03-31' elif 'Q2' if '2017-04-01' =< str(date) =< '2017-06-30' elif 'Q3' if '2017-07-01' =< str(date) =< '2017-09-30' else 'Q4'

 

My issue is that I get an output of Q4 when I try

print quarter

. The output generated should have been Q3 as I ran this today (July 10, 2017). If I change the ending of the code to be

'Q4' if '2017-10-01' =< str(date) =< '2017-12-31'

, the result would be a syntax error. What am I doing wrong and how can I fix it but also stored the if conditional in one line and set it equal to the variable quarter?

Outcomes