Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Field Calculator Script Help

$
0
0
The below script works as expected in PythonWin or any other IDE and I am attempting to adapt it to be used in the Field Calculator (ArcMap 10.1) but I am not getting the expected results.

Expected result: populate the field with sequential values that are text/string representation(s) of dates (in the format YYYYMM).

Current result: no errors, but it just populates with a single date/result and not iterating to the next value in the sequence.

Help is appreciated!

Code:


import datetime
from datetime import timedelta
date=0
def jump_by_month(start_date, end_date, month_step=1):
    current_date = start_date
    while current_date < end_date:
    #yield current_date
    carry, new_month = divmod(current_date.month - 1 + month_step, 12)
    new_month += 1
    current_date = current_date.replace(year=current_date.year + carry, month=new_month)
    yr = current_date.year
    strYR = str(yr)
    mo = current_date.month
    if mo < 10:
      strMO = "0" + str(mo)
    else:
      strMO = str(mo)
   
    retVal =  strYR + strMO
    return retVal


Viewing all articles
Browse latest Browse all 2485

Trending Articles