park = "a park.shp"
road = "the roads.shp"
school = "a school.shp"
train = "the train"
bus = "the bus.shp"
mall = "a mall"
ferry = "the ferry"
viaduct = "a viaduct"
dataList = [park, road, school, train, bus, mall, ferry, viaduct]
print dataList
for a in dataList:
print a
#if a.endswith(".shp"):
# dataList.remove(a)
print dataList
给出以下输出(因此循环正在工作并正确读取所有内容):
['a park.shp', 'the roads.shp', 'a school.shp', 'the train', 'the bus.shp', 'a mall', 'the ferry', 'a viaduct']
a park.shp
the roads.shp
a school.shp
the train
the bus.shp
a mall
the ferry
a viaduct
['a park.shp', 'the roads.shp', 'a school.shp', 'the train', 'the bus.shp', 'a mall', 'the ferry', 'a viaduct']
但是当我删除# 标记以运行 if 语句时,它应该删除以 .shp 结尾的字符串,字符串路径是否保留在列表中?
['a park.shp', 'the roads.shp', 'a school.shp', 'the train', 'the bus.shp', 'a mall', 'the ferry', 'a viaduct']
a park.shp
a school.shp
the bus.shp
the ferry
a viaduct
['the roads.shp', 'the train', 'a mall', 'the ferry', 'a viaduct']
我注意到的其他事情,当它明显处于应该遍历每个字符串的 for 循环中时,它不会打印所有字符串?有人可以解释发生了什么问题,循环保持字符串路径但找到以 .shp 结尾的其他字符串并正确删除它们吗?
谢谢, C
(仅供参考,这是在 Python 2.6.6 上,因为 Arc 10.0)