import arcpy from arcpy import env import os env.workspace = r'C:\Test\Test.gdb' wspce = r'C:\Test\Test.gdb' fc = 'G10' fdName = "SBCID" arcpy.AddField_management(wspce + os.sep + fc, fdName, "STRING") rows = arcpy.UpdateCursor(fc) for i, row in enumerate(rows): row.SBCID = str(i + 1).zfill(3) rows.updateRow(row)
arcpy.CalculateField_management(wspce + os.sep + fc, fdName, '"str(!' + fd.name + '!).zfill(3)"', "PYTHON_9.3", "")
import arcpy from arcpy import env import os env.workspace = r'C:\Test\Test.gdb' wspce = r'C:\Test\Test.gdb' fc = 'G10' fdName = "SBCID" arcpy.AddField_management(wspce + os.sep + fc, fdName, "STRING") fdList = arcpy.ListFields(wspce + os.sep + fc) for fd in fdList: print fd.name, ">>", fd.type print fd arcpy.CalculateField_management(wspce + os.sep + fc, fdName, str(fd.????).zfill(3)) print wspce print os.sep + fc print fdName
for i in range(600): #use range(1,601) to get 1 to 600 str(i).zfill(6)
>>> test = "1" >>> test.zfill(10) '0000000001' >>>
for i in range(1, 600, 1): print ((6 - len(str(i))) * "0") + str(i)
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.