there is a dataset named "DT" in geodatabase and two featureclasses named "A" and "DT" in the dataset, and My code is:
arcpy.env.workspace=gdb
dts=arcpy.ListDatasets()
for dt in dts:
fcs=arcpy.ListFeatureClasses(feature_dataset=dt)
for fc in fcs:
c=arcpy.GetCount_management(fc)
fis=arcpy.ListFields(fc)
fnames=[f.name for f in fis]
arcpy.AddMessage('{} {} {}'.format(fc,c[0],';'.join(fnames))
After run this code, it'll print the correct name and count for both featureclasses but wrong for 'DT' featureclass's fields, as get the same as 'A' featureclass, not actually 'DT' itself's.
I use 10.8.2.
I'm really surprised that you can have a featureclass inside a featuredataset with the same name as the featuredataset. As a first test try renaming the DT featureclass to something else then run your code, what do you get then?
I haven't heard about any rule prohibiting feature class from having the same name as feature dataset - if there is one could you please provide source? Definitely you cannot have 2 feature classes with the same name in different datasets.
Back to the code - it worked well for me, but I have ArcGIS Pro, so there might be some specific bug in ArcMap. For clarity I put the code again in formatted way (please note that there is a missing parenthesis at the end of the original code by leigao):
arcpy.env.workspace=gdb
dts=arcpy.ListDatasets()
for dt in dts:
fcs=arcpy.ListFeatureClasses(feature_dataset=dt)
for fc in fcs:
c=arcpy.GetCount_management(fc)
fis=arcpy.ListFields(fc)
fnames=[f.name for f in fis]
print ('{} {} {}'.format(fc,c[0],';'.join(fnames)))
Sorry for long time in responding. I tested your code and database in ArcGIS Pro (3.2). Works well. If it doesn't work well in ArcMap then it might be ArcMap-specific bug. Code looks OK.