Select to view content in your preferred language

Print subtypes

665
2
12-19-2013 07:49 AM
GwenJakel
Deactivated User
I'm trying to use this script to list subtypes in  a database

for stcode, stdict in subtypes.iteritems():
    print('Code: {0}'.format(stcode))
    for stkey in stdict.iterkeys():
        if stkey == 'FieldValues':
            print('Fields:')
            fields = stdict[stkey]
            for field, fieldvals in fields.iteritems():               
                print(' --Field name: {0}'.format(field))
                print(' --Field default value: {0}'.format(fieldvals[0]))
                if not fieldvals[1] is None:
                    print(' --Domain name: {0}'.format(fieldvals[1].name))
        else:                   
            print('{0}: {1}'.format(stkey, stdict[stkey]))

I keep getting the following error

Runtime error
Traceback (most recent call last):
  File "<string>", line 1, in <module>
NameError: name 'subtypes' is not defined

I'm trying to add the path to my dataset into line 1 (in the parenthesis)

for stcode, stdict in subtypes.iteritems():

Any suggestions would be appreciated.

Thanks
Tags (2)
0 Kudos
2 Replies
JakeSkinner
Esri Esteemed Contributor
Hi Gwen,

How are you adding your path?  It seems you are using the following example:

http://resources.arcgis.com/en/help/main/10.2/index.html#//018w00000021000000

import arcpy

subtypes = arcpy.da.ListSubtypes('C:/data/Boston.gdb/Boundary')

for stcode, stdict in subtypes.iteritems():
    print('Code: {0}'.format(stcode))
    for stkey in stdict.iterkeys():
        if stkey == 'FieldValues':
            print('Fields:')
            fields = stdict[stkey]
            for field, fieldvals in fields.iteritems():                
                print(' --Field name: {0}'.format(field))
                print(' --Field default value: {0}'.format(fieldvals[0]))
                if not fieldvals[1] is None:
                    print(' --Domain name: {0}'.format(fieldvals[1].name))
        else:                    
            print('{0}: {1}'.format(stkey, stdict[stkey]))


When adding a path, you will want to format it one of the following ways:

forward slashes
'C:/data/Boston.gdb/Boundary'


begin with 'r'
r'C:\data\Boston.gdb\Boundary'


double back slashes
'C:\\data\\Boston.gdb\\Boundary'
0 Kudos
AndrewChapkowski
Esri Regular Contributor
Can you please re-post your code so it is formatted properly within the
 tags.  It's hard to read the way you posted it.
0 Kudos