我正在使用 python 2.7 和 arcpy 做一些数据管理。
我正在尝试创建一个脚本来询问用户数据来自哪一年,以便生成文件路径。
while True:
try:
year = int(raw_input("What state fiscal year is this for (yyyy)? "))
except ValueError:
print("Are you daft?!")
continue
if year < 2017:
print("Sorry tool is only compatible with post 2017 files")
elif year > 2030:
print("Someone needs to update the script... it's been over a decade since inception!")
else:
print("Party on!")
break
scriptpath = os.getcwd()
下一行是用户输入进入文件路径的地方,也是抛出错误的行:
folder = "OARS Raw Data\OARS S_FY{0}".format(year[2:])
Type error: 'int' object has no attribute '__ getitem __'
是什么导致它不拉年份值?我尝试分配另一个变量:year1 = year
在脚本路径和文件夹行之间,但仍然出现类型错误。
我应该提到当我在没有 while 循环的情况下分配年份时,文件夹行有效。year = "2018"