>>> import sys ... import arcpy ... import string ... ... reload(sys) ... sys.setdefaultencoding('utf-8') ... ... try: ... workspace = 'C:\\Users\\Administrator\\Desktop\\qwe' ... outdb = 'C:\\Users\\Administrator\\Desktop\\lutian.mdb' ... arcpy.env.workspace = workspace ... files = arcpy.ListFiles('*.*db') ... arcpy.env.workspace = outdb ... fcs = arcpy.ListFeatureClasses() ... fcs = fcs + arcpy.ListTables() ... dss = arcpy.ListDatasets() ... ... for File in files: ... for fc in fcs: ... arcpy.Append_management(workspace + '\\' + File + '\\' + fc, outdb + '\\' + fc) ... ... for ds in dss: ... fcs1 = arcpy.ListFeatureClasses(feature_dataset = ds) ... for fc1 in fcs1: ... arcpy.Append_management(workspace + '\\' + File + '\\' + ds + '\\' + fc1, outdb + '\\' + ds + '\\' + fc1) ... ... except arcpy.ExecuteError: ... print(arcpy.GetMessages()) ... Runtime error Traceback (most recent call last): File "<string>", line 15, in <module> TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
时间: 2024-02-06 20:02:41 浏览: 145
自然资源确权制图.zip
5星 · 资源好评率100%
这段代码中还是出现了字符串连接问题。你需要检查一下fcs和dss这两个变量的值是否为NoneType,如果是的话,你需要在字符串连接之前进行判断,避免出现这种错误。
以下是修改后的代码:
```python
import sys
import arcpy
import string
reload(sys)
sys.setdefaultencoding('utf-8')
try:
workspace = 'C:\\Users\\Administrator\\Desktop\\qwe'
outdb = 'C:\\Users\\Administrator\\Desktop\\lutian.mdb'
arcpy.env.workspace = workspace
files = arcpy.ListFiles('*.*db')
arcpy.env.workspace = outdb
# 判断fcs和dss是否为NoneType
fcs = arcpy.ListFeatureClasses()
if fcs is not None:
fcs = fcs + arcpy.ListTables()
else:
fcs = []
dss = arcpy.ListDatasets()
if dss is None:
dss = []
for File in files:
for fc in fcs:
arcpy.Append_management(workspace + '\\' + File + '\\' + fc, outdb + '\\' + fc)
for ds in dss:
fcs1 = arcpy.ListFeatureClasses(feature_dataset = ds)
for fc1 in fcs1:
arcpy.Append_management(workspace + '\\' + File + '\\' + ds + '\\' + fc1, outdb + '\\' + ds + '\\' + fc1)
except arcpy.ExecuteError:
print(arcpy.GetMessages())
```
修改后的代码中,在对fcs和dss进行赋值之后,加入了判断是否为NoneType的代码。如果是,则将其赋值为空列表。这样可以避免出现字符串连接问题。
阅读全文