我是新來的Python腳本,我主要用它在ArcGIS 10.我的腳本應該重新格式化內的一個字符串字段CINTP1。一個例子是'000000100'並返回'1.00'。我已經將它導入到工具箱中,以在表格'MAPCHAR'內的選定記錄上運行。我一直recieveing的錯誤是:的Python腳本在ArcGIS 10是使用模塊重新並返回「沒有定義的全局名稱‘重’」
:ERROR 000539:錯誤運行表達式:removeLeadingZeros( 「000000100」):全球名稱 '重' 沒有定義 無法執行(CalculateField)。
無法執行(腳本)。
這裏是我的腳本:
import arcpy, re, sys, string, os
MAPCHAR = "MAPCHAR"
CINPT1 = "CINPT1"
expression = "removeLeadingZeros(!CINPT1!)"
codeblock = """def removeLeadingZeros(myValue):
newValue = re.sub('^0+',"",myValue)
valueList = list(newValue) #convert newValue to List
valueList.insert(-2, '.') #insert the '.' characater int the list at the -2 position
newValue = "".join(valueList) #join back to create the new updated string
myvalue = newValue"""
arcpy.CalculateField_management(MAPCHAR, CINPT1, expression, "Python", codeblock)
任何幫助將是appreciated..thanks,
我認爲你需要import語句添加到您的字符串'codeblock' .. –