I'm trying to manipulate data stored in a table. The table columns have Swedish names with Å,Ä or Ö.
Python Shell can print the characters but when i store them in a list they wont work:
>>> print 'åäö'
>>> testlist = ['åäö', 'öööö']
>>> import sys
>>> testlist = ['åäö','ööö']
>>> for x in testlist:
with arcpy.da.UpdateCursor(fc, fieldlist) as ucursor:
for row in ucursor:
When printing lists, note that
__str__ (which is implicitly called by
__repr__ in order to display them. There seems to be nothing wrong. Check:
>>> testlist = ['åäö', 'öööö'] >>> print testlist ['\xc3\xa5\xc3\xa4\xc3\xb6', '\xc3\xb6\xc3\xb6\xc3\xb6\xc3\xb6'] >>> for x in testlist: ... print x, repr(x) ... åäö '\xc3\xa5\xc3\xa4\xc3\xb6' öööö '\xc3\xb6\xc3\xb6\xc3\xb6\xc3\xb6'
When you are dealing with non-ascii characters, it is often better to use unicode strings. They are more well-behaved:
>>> len('öäü') 6 >>> len(u'öäü') 3 >>> s = 'äöü' >>> s_u = s.decode('utf-8') >>> s '\xc3\xa4\xc3\xb6\xc3\xbc' >>> s_u u'\xe4\xf6\xfc' >>> s == s_u False