<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to write a if conditional stored in a variable? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597268#M46777</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Vishal,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is why I like the function method, you can just use the date-time module and not have to alter your code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;~Alex&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 10 Jul 2017 18:51:39 GMT</pubDate>
    <dc:creator>AlexanderBrown5</dc:creator>
    <dc:date>2017-07-10T18:51:39Z</dc:date>
    <item>
      <title>How to write a if conditional stored in a variable?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597259#M46768</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;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:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; datetime

date &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; datetime&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;today&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;

quarter &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Q1'&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'2017-01-01'&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'2017-03-31'&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;elif&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Q2'&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'2017-04-01'&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'2017-06-30'&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;elif&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Q3'&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'2017-07-01'&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'2017-09-30'&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Q4'&lt;/SPAN&gt;‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My issue is that I get an output of Q4 when I try&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt; quarter‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;. 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&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="string token"&gt;'Q4'&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'2017-10-01'&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;lt;&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'2017-12-31'&lt;/SPAN&gt;‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;, 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?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:38:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597259#M46768</guid>
      <dc:creator>VishalShah2</dc:creator>
      <dc:date>2021-12-12T01:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a if conditional stored in a variable?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597260#M46769</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is a complex set of conditional statements that should really be on separate lines. However, since&amp;nbsp;your date is already&amp;nbsp;a datetime object, &lt;A href="https://stackoverflow.com/a/1406182" rel="nofollow noopener noreferrer" target="_blank"&gt;some simple math&lt;/A&gt;&amp;nbsp;will determine the quarter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;date &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; datetime&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;today&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
quarter &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Q{}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;month&lt;SPAN class="number token"&gt;-1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;//&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;3&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt; quarter‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:38:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597260#M46769</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-12-12T01:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a if conditional stored in a variable?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597261#M46770</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;d &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'2017-01-01'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'2017-03-31'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'2017-06-30'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'2017-09-30'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'2017-12-31'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
qs &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;''&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Q1'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Q2'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Q3'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Q4'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
dts &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'2017-03-30'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'2017-04-02'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'2017-09-30'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'2017-12-12'&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; i &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; dts&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; lt &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;i &lt;SPAN class="operator token"&gt;&amp;lt;=&lt;/SPAN&gt; j &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; j &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; d&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; q &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; qs&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;-&lt;/SPAN&gt;sum&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;lt&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Date: {}, Quarter {}"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;format&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;i&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; q&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This example just assumes a list of dates.. modify as needed.&amp;nbsp; basic reverse slicing is used, hence the extra '' in the quarters list (qs) and Ijust included the upper date for the quarter dates (dts).&amp;nbsp; you could get this into a single list comprehension, but I am not sure that you need to go that far&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:38:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597261#M46770</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-12T01:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a if conditional stored in a variable?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597262#M46771</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Based on the responses in the other forum, something like this should work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; m &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; range&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;13&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;m&lt;SPAN class="number token"&gt;-1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;/&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;3&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;where the outcome is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;2&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;2&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;2&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;3&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;3&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;3&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;4&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;4&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;4&lt;/SPAN&gt;‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I can't think of a way that will take my date = datetime.date.today() &amp;nbsp;and use the math they provided on that to check over my date to determine which quarter it belongs to.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;**UPDATE**&lt;/P&gt;&lt;P&gt;Based on Blake's update, this may be the easiest solution.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:38:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597262#M46771</guid>
      <dc:creator>VishalShah2</dc:creator>
      <dc:date>2021-12-12T01:38:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a if conditional stored in a variable?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597263#M46772</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Vishal,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From this example:&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://stackoverflow.com/questions/36793381/python-get-first-and-last-day-of-current-calendar-quarter" title="https://stackoverflow.com/questions/36793381/python-get-first-and-last-day-of-current-calendar-quarter" rel="nofollow noopener noreferrer" target="_blank"&gt;Python get first and last day of current calendar quarter - Stack Overflow&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can do something like:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; bisect
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; datetime &lt;SPAN class="keyword token"&gt;as&lt;/SPAN&gt; dt

&lt;SPAN class="keyword token"&gt;def&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;get_quarter&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; today &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; dt&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;today&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; qbegins &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;dt&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;today&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;year&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; month&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; month &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;4&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;7&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;10&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; quarter &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; bisect&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;bisect&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;qbegins&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; today&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; quarter
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;## Following line will return first day of the quarter&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="comment token"&gt;# return str(qbegins[idx-1])&lt;/SPAN&gt;


quarter_id &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; get_quarter&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt; quarter_id
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;~Alex&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:38:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597263#M46772</guid>
      <dc:creator>AlexanderBrown5</dc:creator>
      <dc:date>2021-12-12T01:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a if conditional stored in a variable?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597264#M46773</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Alexander,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you so much! I wasn't aware of bisect in python or it's functionality but I tried it the way you recommended it except instead of doing import datetime as dt, I left it as import datetime only and used my predefined date variable instead of today. still resulted in getting the right value!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jul 2017 18:24:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597264#M46773</guid>
      <dc:creator>VishalShah2</dc:creator>
      <dc:date>2017-07-10T18:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a if conditional stored in a variable?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597265#M46774</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am not sure why you want to have it all as a 1 line. &amp;nbsp;It makes it very hard to read. &amp;nbsp;But if you must then use this code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; arcpy
&lt;SPAN class="keyword token"&gt;import&lt;/SPAN&gt; datetime

date &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; datetime&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;today&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
quarter &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Q1'&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'2017-01-01'&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;=&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;and&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'2017-03-31'&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Q2'&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'2017-04-01'&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;=&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;and&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'2017-06-30'&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Q3'&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'2017-07-01'&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;=&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;and&lt;/SPAN&gt; str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;date&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;&amp;lt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'2017-09-30'&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;'Q4'&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You had several things wrong. &amp;nbsp;First, the &amp;lt;= was backwards (you had =&amp;lt;). &amp;nbsp;Secondly, you can't do 1 &amp;gt; x &amp;gt; 3. &amp;nbsp;It has to be 1 &amp;gt; x and x &amp;gt; 3. &amp;nbsp;Finally, when you do 1 line if statements, you need to use else, not elif since you are basically doing nested if statements. &amp;nbsp;Hopefully this helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 01:38:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597265#M46774</guid>
      <dc:creator>KevinDunlop</dc:creator>
      <dc:date>2021-12-12T01:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a if conditional stored in a variable?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597266#M46775</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for that Kevin! I am contemplating between using your method and Alexander's. As you said, having it in one line makes it harder to read (but your method is in my opinion a bit more simple compared to having to define a function).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jul 2017 18:31:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597266#M46775</guid>
      <dc:creator>VishalShah2</dc:creator>
      <dc:date>2017-07-10T18:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a if conditional stored in a variable?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597267#M46776</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Kevin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On a slightly separate note, is it possible to make the year a rolling year? For example, leaving 2017 for now is fine, but say it gets to be 2018, would I have to go back into the code to change the year manually, or can the year change in the code by what year it's in?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jul 2017 18:38:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597267#M46776</guid>
      <dc:creator>VishalShah2</dc:creator>
      <dc:date>2017-07-10T18:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a if conditional stored in a variable?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597268#M46777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Vishal,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is why I like the function method, you can just use the date-time module and not have to alter your code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;~Alex&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jul 2017 18:51:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597268#M46777</guid>
      <dc:creator>AlexanderBrown5</dc:creator>
      <dc:date>2017-07-10T18:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a if conditional stored in a variable?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597269#M46778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree Alexander, realized that after I had responded to Kevin's approach. As of right now, I have my tool set to the function method you provided. Made notes of the method tat Blake suggested too (that one I don't think you have to alter the code on a yearly basis).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jul 2017 18:54:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597269#M46778</guid>
      <dc:creator>VishalShah2</dc:creator>
      <dc:date>2017-07-10T18:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a if conditional stored in a variable?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597270#M46779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just glad we could help you out! Now you have a lot of options.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;~Alex&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jul 2017 18:55:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597270#M46779</guid>
      <dc:creator>AlexanderBrown5</dc:creator>
      <dc:date>2017-07-10T18:55:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a if conditional stored in a variable?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597271#M46780</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Much appreciated! Thank you once again!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jul 2017 18:57:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597271#M46780</guid>
      <dc:creator>VishalShah2</dc:creator>
      <dc:date>2017-07-10T18:57:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a if conditional stored in a variable?</title>
      <link>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597272#M46781</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;While we are on the topic of time....&amp;nbsp;&lt;A _jive_internal="true" href="https://community.esri.com/blogs/richard_fairhurst/2016/07/01/ive-saved-time-in-a-bottle-how-do-i-get-it-back-out-doing-more-with-date-fields-using-the-field-calculator-and-python"&gt;Richard Fairhurst's blog ... I've saved time in a bottle ...how do i get it back out doing more with date fields using the field calculator and python&lt;/A&gt; totally forgot about that one.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Jul 2017 19:17:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-write-a-if-conditional-stored-in-a-variable/m-p/597272#M46781</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-07-10T19:17:31Z</dc:date>
    </item>
  </channel>
</rss>

