Using Multivalue Inputs List

385
3
10-11-2011 08:21 PM
DanikBourdeau
New Contributor III
I am having issues trying to get a list of multivalue input working.

Here is my code:

import arcpy

tbl = arcpy.GetParameterAsText(0)
wrksp = arcpy.GetParameterAsText(1)

for i in tbl.split(";"):
    arcpy.TableToTable_conversion(i, wrksp, "temp1.dbf")

For some reason the script will always crash saying the dataset does not exist.  The reason being is that the string returned has ' ' around it so the path name is not right.

Anybody know a work around?

Thanks

P.S.  How do I put my code above in a special box like everyone else seems to do?
0 Kudos
3 Replies
DanikBourdeau
New Contributor III
Well, I was able to solve my problem by using t = i.replace("'", "") which removes the ' everywhere allowing the tool to accept the input.

But I still find it strange that the TableToTable tool won't accept the input as is with ' around it.
0 Kudos
curtvprice
MVP Esteemed Contributor
Well, I was able to solve my problem by using t = i.replace("'", "") which removes the ' everywhere allowing the tool to accept the input.

But I still find it strange that the TableToTable tool won't accept the input as is with ' around it.


This is a problem with the text representation of the parameter. Each entry in the list is quoted to ensure it can be somehow parsed, though if the there was a ';' in any of the inputs I'm thinking it would break the python .split().

A safer way to unpack a list of values is to bypass the string representation using GetParameter() instead of GetParameterAsText. Then instead of a string you get a value table which can then be parsed using the value table object methods:

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v000000q1000000

If there's a new arcpy way to do it that's better, someone please chime in!
0 Kudos
RussellBrennan
Esri Contributor


P.S.  How do I put my code above in a special box like everyone else seems to do?


There is a button when you are replying that looks like # it will put [noparse]
[/noparse] tags around your selected text.
					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
0 Kudos