python encoding problem?

979
2
09-25-2013 01:27 AM
LiborHladis
New Contributor
Hello, I know that this theme was discussed few times, but I didnt solve the problem using informations that I've found here.

There is (for many of you well known) problem with coding.

<type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode character u'\xa0' in position 11: ordinal not in range(128)

I enter ID number (data type string) but the script ends with error.
I have tried .encode('utf-8'), .replace(u'\xa0', ' ') but it was no solution.

First - problematic - part of the script is below:

import arcpy, sys, os, shutil
from arcpy import env

arcpy.env.overwriteOutput = True

obecJmeno = arcpy.GetParameter(0)
adr_puvodni = u"C:\\vydej2\\mapy_!empty_2013"
adr_nove="C:\\vydej2\\Data_Export\\mapy_"+obecJmeno+"_2013"
vyberZ=arcpy.GetParameter(1)
ID=arcpy.GetParameter(2)
if vyberZ=="obec":
    vyber= "C:\\vydej2\\Data\\CZ020STCE11obc_poly.shp"
    sqlstat= "\"KOD_OBC_TX\"=" + "'" + ID+ "'"
elif vyberZ=="opu":
    vyber= "C:\\vydej2\\Data\\CZ020STCE11opu_poly.shp"
    sqlstat= "\"KOD_OPU_TX\"=" + "'" + ID+ "'"
    
        etc


Any ideas please?

Btw - this script was fully working yesterday on my collegues computer. Today it doesnt work at his PC as well as at mine.

ArcGIS 10.0 build 4400
Tags (2)
0 Kudos
2 Replies
curtvprice
MVP Esteemed Contributor
You provided no specifics as to how you were getting the parameters - command line, script tool, modelbuilder, etc???

I suggest trying arcpy.GetParameterAsText(), which gives you a string representation instead of an object.

Text is often much easier to work with (for one thing, you can print it out and look at it with repr() -- so you can at least see what you have).
0 Kudos
LiborHladis
New Contributor
I tried to use arcpy.GetParameterAsText()  but result is still the same.

From my opinion the problem is in dbf coding (cp1250) because when I have script without parameters and run it in Python shell, it works.

I was getting the parameters using script tool.

I am new in python so maybe I didn't write some important things...
0 Kudos