>>> 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 15:02:13 浏览: 314
这段代码中出现了两个问题,一个是缩进问题,一个是字符串连接问题。以下是修改后的代码。
```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 = 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())
```
修改后的代码中,缩进问题已经被修复,并且修改了字符串连接方式,使用双反斜杠来转义路径中的反斜杠,防止出现字符串连接问题。另外,在except语句中,使用了print函数来输出错误信息。
阅读全文