3

I have a large list of coded domains.

They are numbers like: 01.6530.01, 05.7991.08, 05.7991.01, 05.7991.06

The code will be the exact same as the description.

I've tried to make a list using:

FRClist = [01.6530.**01**, 05.7991.08, 05.7991.01, 05.7991.06]

but it gave me a syntax error on the 01 that is bolded.

So I tried to change all the values to a string, using:

FRCstr = str(01.6530.**01**, 05.7991.08, 05.7991.01, 05.7991.06)

but it still gave me a syntax error on the same bolded 01.

In the end I hope to put the list into this:

arcpy.AddCodedValueToDomain_management(GDBpath, "FRC", FRClist[x], FRClistp[x] )

I have quite a few domains which require a lot of coded values.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 4, 2012 at 22:06
1
  • 3
    If by chance you already have the values in a table then you may find it easier to use the Table to Domain tool. Commented Nov 4, 2012 at 22:19

1 Answer 1

2

In the Add Coded Value To Domain documentation there are code examples that show you how to do this. It looks like you are trying to submit a list of coded values to a function that is designed to take a coded value at a time. I think you should change your code to iterate through your list instead.

Python will not like 01.6530.01 being treated as a number because it is not a number. To treat it as a string I think you will need to use the str function on each value you add to the list rather than trying to turn the list as a whole into a string.

answered Nov 4, 2012 at 22:24
4
  • 2
    If you use the csv module I think they will be automatically interpreted as strings. No need to manually add quotes. Commented Nov 4, 2012 at 22:44
  • 2
    Also I believe the Table to Domain tool (TableToDomain_management function in arcpy) can read a CSV file directly as the input table. You'll want to separate records in a CSV file by new lines though. So if the only column you have is your list of values, put each value on its own line. Commented Nov 4, 2012 at 22:45
  • You said that you had the list in a txt file so why not use a throwaway Python script to take the values in that file and reformat with quotes or str functions onto a single line of a throwaway file that you can copy/paste into the actual script. Commented Nov 4, 2012 at 23:23
  • 1
    Why the arbitrary restriction of no external files? This is getting pretty off-topic for this site BTW. Commented Nov 4, 2012 at 23:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.