I am learning Python to create toolbox right now. When I'm trying to get the parameter, using valueAsText, the date returned is unicode instead of a list that I was expecting.

This is the code that I was using:

inFeatures = parameters[0].valueAsText

I was hoping the input data would be stroed in a list in this way, put when I use for loop, this is what I have:

    for inFeature in inFeatures:

enter image description here

It is dividing the path into single characters.

Any way I could get the result in a list?

  • 3
    I think we need a few more details. What version of ArcGIS for Desktop are you using? Are you writing a Python toolbox or a Python script tool in a standard toolbox? What shows up when you AddMessage str(inFeatures)? – PolyGeo Nov 30 '14 at 21:08
  • Generally I use sys.argv[index] to get parameters, either from command line or arctoolbox, unless there's a specific reason why that will not be the best choice. Please also include your platform (MS Windows (any version), Linux (what flavor) or Mac)... parameter passing is close to the operating system and they all do things differently. Based on what you're experiencing I'd say you're on MS Windows as parameters are passed as Unicode by that OS. There's some more reading material here stackoverflow.com/questions/2365411/… that might help. – Michael Stimson Nov 30 '14 at 22:26
  • Thank you for your reply, I am using ArcGIS 10.2 on Windows 8.1 64bit. I was using the Python toolbox when I was using inFeatures = parameters[0].valueAsText. When I used AddMessage str(inFeatures), it become string. Now I need to input multi Value, and I am trying to use Python script, and trying to use sys.argv[index]. But it in this way or use str(inFeatures), everything become a string, but I want this to be a list, one element for each input feature class. Thanks – Orion Lullaby Dec 1 '14 at 0:36
  • I know it becomes a string but I was wanting to see what the contents of your variable looked like when you converted it to a string so that it could be printed/AddMessage-d. Please be aware that there is an edit button beneath your question which enables you to revise (i.e. improve) it in response to comments. It may be worth reviewing What makes a good question?. – PolyGeo Dec 1 '14 at 4:28

Its just the way python iterates over lists and/or strings.

>>> l = ["Fred"]
>>> for i in l:
    print i

>>> l = "Fred"
>>> for i in l:
    print i


inFeatures contains 1 item, the string "E:/Documents". If necessary, create a list first (l = []), then append items to it.

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.