Print a list of SDE datasources

629
4
Jump to solution
07-02-2014 07:49 AM
RebeccaWatson
Occasional Contributor
Hi,
I am trying to print out a list of SDE datasources used by some MXDs in a folder. I can successfully print out a list of all the datasources, but I am having no luck separating out the sde connections. I have tried the following and a few other variations on the theme but I can't get anything to print out:

for lyr in arcpy.mapping.ListLayers(mxd):      if lyr.supports("WORKSPACEPATH"):           wsp = lyr.workspacePath           if wsp == ("*.sde"):                print lyr.dataSource


It seems like this should be pretty straight forward but I'm having no luck.
Can anyone point me in the right direction?
Thanks
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
markdenil
Regular Contributor II
I would suggest that
if wsp == ("*.sde"):
is not a useful test.

perhaps
if wsp.endswith('.sde'):
would serve better

It is, by the way, perfectly fine to test a boolean baldly, as in:
if True: do something

View solution in original post

0 Kudos
4 Replies
IanMurray
Frequent Contributor
It may or may not be this simply but

if lyr.supports("WORKSPACEPATH"):

might need to be

if lyr.supports("WORKSPACEPATH") == True:

since the support method returns a Boolean data type.  Currently you are not actually checking it against anything for the if statement.
0 Kudos
markdenil
Regular Contributor II
I would suggest that
if wsp == ("*.sde"):
is not a useful test.

perhaps
if wsp.endswith('.sde'):
would serve better

It is, by the way, perfectly fine to test a boolean baldly, as in:
if True: do something

View solution in original post

0 Kudos
IanMurray
Frequent Contributor
Thanks for the python nugget Mark, I thought that my suggestion was a bit too simple, but it was the only thing that struck me when i looked at it.
0 Kudos
RebeccaWatson
Occasional Contributor
Thanks Mark that's done the trick, they are listing perfectly now.
0 Kudos