Using ListUsers—Help | ArcGIS Desktop as my reference I'm trying to get a list of users connected to an eGDB that I can iterate through.
The online help page suggests:
<SPAN class="comment token"># Set the admistrative workspace connection</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Database Connections/tenone@sde.sde"</SPAN>
<SPAN class="comment token"># Create a list of users</SPAN>
<SPAN class="string token">'''
NOTE: When the arcpy.env.workspace environment is set, a workspace
does not need to be provided to the function.
'''</SPAN>
users <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListUsers<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
However, my attempt errors out:
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'I:\PathTo\SdeUserConnection\sde@My.sde'</SPAN>
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> users <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListUsers<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
Runtime error
Traceback <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
File <SPAN class="string token">"<string>"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>module<SPAN class="operator token">></SPAN>
TypeError<SPAN class="punctuation token">:</SPAN> ListUsers<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> takes exactly <SPAN class="number token">1</SPAN> argument <SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN> given<SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
If I specify the workspace and output it to a variable name, I get a list of tuples, which is cool, but then I have to step through it and tease out what I want:
ws <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="comment token">#set in line 1 above...</SPAN>
users <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListUsers<SPAN class="punctuation token">(</SPAN>ws<SPAN class="punctuation token">)</SPAN>
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> users
<SPAN class="punctuation token">[</SPAN>user<SPAN class="punctuation token">(</SPAN>ClientName<SPAN class="operator token">=</SPAN>u<SPAN class="string token">'ad-trasmussen:10.5.1.7333'</SPAN><SPAN class="punctuation token">,</SPAN> ConnectionTime<SPAN class="operator token">=</SPAN>datetime<SPAN class="punctuation token">.</SPAN>datetime<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2018</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">22</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">14</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> ID<SPAN class="operator token">=</SPAN><SPAN class="number token">388635</SPAN><SPAN class="punctuation token">,</SPAN> IsDirectConnection<SPAN class="operator token">=</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">,</SPAN> Name<SPAN class="operator token">=</SPAN>u<SPAN class="string token">'"SLCOUNTY\\TARASMUSSEN"'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> user<SPAN class="punctuation token">(</SPAN>ClientName<SPAN class="operator token">=</SPAN>u<SPAN class="string token">'AD-TBAIN-10:10.5.1.7333'</SPAN><SPAN class="punctuation token">,</SPAN> ConnectionTime<SPAN class="operator token">=</SPAN>datetime<SPAN class="punctuation token">.</SPAN>datetime<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2018</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">22</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">13</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> ID<SPAN class="operator token">=</SPAN><SPAN class="number token">388636</SPAN><SPAN class="punctuation token">,</SPAN> IsDirectConnection<SPAN class="operator token">=</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">,</SPAN> Name<SPAN class="operator token">=</SPAN>u<SPAN class="string token">'"SLCOUNTY\\TBAIN"'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> user<SPAN class="punctuation token">(</SPAN>ClientName<SPAN class="operator token">=</SPAN>u<SPAN class="string token">'ad-trasmussen:10.5.1.7333'</SPAN><SPAN class="punctuation token">,</SPAN> ConnectionTime<SPAN class="operator token">=</SPAN>datetime<SPAN class="punctuation token">.</SPAN>datetime<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2018</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">22</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">11</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">12</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> ID<SPAN class="operator token">=</SPAN><SPAN class="number token">388637</SPAN><SPAN class="punctuation token">,</SPAN> IsDirectConnection<SPAN class="operator token">=</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">,</SPAN> Name<SPAN class="operator token">=</SPAN>u<SPAN class="string token">'"SLCOUNTY\\TARASMUSSEN"'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> user<SPAN class="punctuation token">(</SPAN>ClientName<SPAN class="operator token">=</SPAN>u<SPAN class="string token">'AD-TBAIN-10:10.5.1.7333'</SPAN><SPAN class="punctuation token">,</SPAN> ConnectionTime<SPAN class="operator token">=</SPAN>datetime<SPAN class="punctuation token">.</SPAN>datetime<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2018</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">22</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">8</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">11</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">32</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> ID<SPAN class="operator token">=</SPAN><SPAN class="number token">388638</SPAN><SPAN class="punctuation token">,</SPAN> IsDirectConnection<SPAN class="operator token">=</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">,</SPAN> Name<SPAN class="operator token">=</SPAN>u<SPAN class="string token">'"SLCOUNTY\\TBAIN"'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> user<SPAN class="punctuation token">(</SPAN>ClientName<SPAN class="operator token">=</SPAN>u<SPAN class="string token">'AD-BLECHEMINANT:10.5.1.7333'</SPAN><SPAN class="punctuation token">,</SPAN> ConnectionTime<SPAN class="operator token">=</SPAN>datetime<SPAN class="punctuation token">.</SPAN>datetime<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2018</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">22</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">10</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">39</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">34</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> ID<SPAN class="operator token">=</SPAN><SPAN class="number token">388640</SPAN><SPAN class="punctuation token">,</SPAN> IsDirectConnection<SPAN class="operator token">=</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">,</SPAN> Name<SPAN class="operator token">=</SPAN>u<SPAN class="string token">'"SLCOUNTY\\BLECHEMINANT"'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> user<SPAN class="punctuation token">(</SPAN>ClientName<SPAN class="operator token">=</SPAN>u<SPAN class="string token">'is-jborgione-10:10.5.1.7333'</SPAN><SPAN class="punctuation token">,</SPAN> ConnectionTime<SPAN class="operator token">=</SPAN>datetime<SPAN class="punctuation token">.</SPAN>datetime<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2018</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">6</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">22</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">11</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">30</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">20</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> ID<SPAN class="operator token">=</SPAN><SPAN class="number token">388641</SPAN><SPAN class="punctuation token">,</SPAN> IsDirectConnection<SPAN class="operator token">=</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">,</SPAN> Name<SPAN class="operator token">=</SPAN>u<SPAN class="string token">'SDE'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN>len<SPAN class="punctuation token">(</SPAN>users<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="keyword token">print</SPAN> users<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token">#prints the user name</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
But I'd rather not do that if I don't have to: I'd much rather use the list object/methods to step through so I can get user.name or user.ID
What's the secret to get arcpy.ListUsers() to work as advertised?