4

I am using Win server 2012 R2 and ArcGIS 10.2.2.

goal: match field names across featureclasses/tables in gdb

I thought that using python to retrieve field names from all featureclasses/tables in a gdb and then convert them to hex would allow me to easily compare and match similar features/tables for a data management exercise. I was wrong.

here's the code:

import os
arcpy.env.workspace= r"C:\Users\$user$\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\connection.sde"

feature_classes = arcpy.ListFeatureClasses()

for fc in feature_classes:
    fieldnames = arcpy.ListFields(fc)
    print fc
    for f in fieldnames:
        print (hex(f.name))

I get this error: Traceback (most recent call last): File "", line 10, in TypeError: hex() argument can't be converted to hex

Print statements are there to help me keep track. According to esri's documentation. ListFields(fc).name should return a string. However it seems to be a object.

  • You can also do field_names = [hex(f.name) for f in arcpy.ListFields(fc)] – BERA Dec 11 '17 at 12:00
5

To see that you are encountering a Python rather than ArcPy error try this:

print(hex("ABC"))

I think you will see:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    print(hex("ABC"))
TypeError: hex() argument can't be converted to hex

Python cannot convert a string to hex using its hex function.

ListFields returns field objects, and from a field object you can get its name as a string by using its name property.

  • Hi PolyGeo, thank you for your prompt reply. I thought this was a Arcpy problem as I was accessing the ListFields objects, not the string within the name object. Thank you for clarifying that. Python can convert string to hex using some help: import os arcpy.env.workspace = r"C:\Users\%user$\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\gisview.sde" feature_classes = arcpy.ListFeatureClasses() for fc in feature_classes: fieldnames = arcpy.ListFields(fc) print fc for f in fieldnames: for l in f.name: print (''.join([hex(ord(l)) for l in f.name])) – MisshapenFile Dec 11 '17 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.