I want to connect a remote sever via python code ,my code is :
arcpy.env.workspace = r"Database Connections\Connection to 10.246.146.120.sde" wk = r"Database Connections\Connection to 10.246.146.120.sde"def list_feature_batch1(pathsde): env.workspace = pathsde # print arcpy.env.workspace datasets = arcpy.ListDatasets() datasets = [''] + datasets if datasets is not None else [] #print datasets wklst = [] for ds in datasets: # print ds # env.workspace = env.workspace + os.sep + ds wk = env.workspace + os.sep + ds # print env.workspace wklst.append(wk) return wklst
# print arcpy.env.workspace
# database = 'Database Connections\\Connection to 10.246.146.120.sde'
# versions = arcpy.ListVersions(database)
for dataset in list_feature_batch1(wk):
print dataset
......
list_feature_batch1 is a function,it works well.
why doesnot the code work,but when I add code that arcpy.env.workspace = r"Database Connections\Connection to 127.0.0.1.sde
the code can run correctly.
It is difficult to comment on what might be happening when the core of the issue seems to revolve around the list_feature_batch1 code, and none of that code is provided.
def list_feature_batch1(pathsde): env.workspace = pathsde # print arcpy.env.workspace datasets = arcpy.ListDatasets() datasets = [''] + datasets if datasets is not None else [] #print datasets wklst = [] for ds in datasets: # print ds # env.workspace = env.workspace + os.sep + ds wk = env.workspace + os.sep + ds # print env.workspace wklst.append(wk) return wklst
Hi lm zh,
A requirement for serveral list functions is for the environment to be set first (i.e. using arcpy.env.workspace). See the following link:
ListFeatureClasses—ArcPy Functions | ArcGIS Desktop
Thanks your reply. I set workspace as following: arcpy.env.workspace =r"Database Connections\Connection to 10.246.146.120.sde" first, but running code has not result. however,adding the code which is
arcpy.env.workspace = r"Database Connections\Connection to 127.0.0.1.sde,the entire code can work correctly.why?
Does the SDE connection file with 10. in the name work if you use it in ArcCatalog?
I connect sde file with arcmap10.6.1,datebase is oracle11g