在 Python 中打印行
Printng row in Python
我已经使用游标创建了一个新属性 table python 和 arcpy 但是当我尝试从属性数据(例如国家/地区、城市和人口)打印行时只有一个将打印城市。
arcpy.CopyRows_management (folder_path + '\NA_Cities.shp', folder_path + '\Select_Cities.dbf')
fc = folder_path + '\Select_Cities.dbf'
The_cursor = arcpy.da.UpdateCursor(fc, ['CNTRY_NAME', 'Population'])
for row in The_cursor:
if row[0] == 'United States' and row[1] < 8000000:
The_cursor.deleteRow()
elif row [0] == 'Mexico' and row[1] < 8000000:
The_cursor.deleteRow()
elif row[0] == 'Canda' and row[1] < 3000000:
The_cursor.deleteRow()
print row
这是我的结果
Selecting locations
Please Stand By...
Removing the data that does not meet the requirements
[u'Canada', 25000.0]
Finished identifying the cities
提前感谢您的任何建议!
要在循环中打印 each 行,print row
语句需要在循环内。
for row in The_cursor:
print row
if row[0] == 'United States' and row[1] < 8000000:
The_cursor.deleteRow()
elif row [0] == 'Mexico' and row[1] < 8000000:
The_cursor.deleteRow()
elif row[0] == 'Canada' and row[1] < 3000000:
The_cursor.deleteRow()
如果您只想打印已删除的行,请将 print
语句放在 if
/elif
条件中。
我已经使用游标创建了一个新属性 table python 和 arcpy 但是当我尝试从属性数据(例如国家/地区、城市和人口)打印行时只有一个将打印城市。
arcpy.CopyRows_management (folder_path + '\NA_Cities.shp', folder_path + '\Select_Cities.dbf')
fc = folder_path + '\Select_Cities.dbf'
The_cursor = arcpy.da.UpdateCursor(fc, ['CNTRY_NAME', 'Population'])
for row in The_cursor:
if row[0] == 'United States' and row[1] < 8000000:
The_cursor.deleteRow()
elif row [0] == 'Mexico' and row[1] < 8000000:
The_cursor.deleteRow()
elif row[0] == 'Canda' and row[1] < 3000000:
The_cursor.deleteRow()
print row
这是我的结果
Selecting locations
Please Stand By...
Removing the data that does not meet the requirements
[u'Canada', 25000.0]
Finished identifying the cities
提前感谢您的任何建议!
要在循环中打印 each 行,print row
语句需要在循环内。
for row in The_cursor:
print row
if row[0] == 'United States' and row[1] < 8000000:
The_cursor.deleteRow()
elif row [0] == 'Mexico' and row[1] < 8000000:
The_cursor.deleteRow()
elif row[0] == 'Canada' and row[1] < 3000000:
The_cursor.deleteRow()
如果您只想打印已删除的行,请将 print
语句放在 if
/elif
条件中。