Hi,
I couldn't figure out why arcpy.ListFeatureClasses() doesn't work when I set env.workspace = os.path.join (path,gdb)
and works when I set env.workspace = r"path to the gdb"!
here is an example:
The below script works in my IDE
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="comment token">#Solution 1</SPAN>
gdbANDpath<SPAN class="operator token">=</SPAN>r<SPAN class="string token">"C:\ahmad data\data\MyProject5\f.gdb"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace<SPAN class="operator token">=</SPAN>gdbANDpath
fclist<SPAN class="operator token">=</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> len<SPAN class="punctuation token">(</SPAN>fclist<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></SPAN><SPAN></SPAN></SPAN>
prints >> 8
while the following script doesn't work and gives an error:
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> os
<SPAN class="comment token">#Solution 2</SPAN>
gdb_name<SPAN class="operator token">=</SPAN><SPAN class="string token">"f.gdb"</SPAN>
gbd_path<SPAN class="operator token">=</SPAN><SPAN class="string token">"C:\ahmad data\data\MyProject5"</SPAN>
gdbANDpath<SPAN class="operator token">=</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>gdb_name<SPAN class="punctuation token">,</SPAN>gbd_path<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace<SPAN class="operator token">=</SPAN>gdbANDpath
fclist<SPAN class="operator token">=</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> len<SPAN class="punctuation token">(</SPAN>fclist<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></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Traceback (most recent call last):
File "<module1>", line 31, in <module>
TypeError: object of type 'NoneType' has no len()
>>>
fclist here returns none and fails to create a list of feature classes in the gdb!
PS: Tested on ArcMap 10.7.1 and 10.6.1, on more than one gdb