import codecs import sys aninput = sys.argv[1] textfile = codecs.open("testfile","wt","utf-8") textfile.write(u"é") # this works textfile.write(aninput) # this fails assuming that aninput = "é" textfile.close()
Solved! Go to Solution.
aninput = sys.argv[1].decode(sys.getfilesystemencoding())
aninput = sys.argv[1].decode(sys.getfilesystemencoding())
Hi Alan,
I continue to get the following error:
<type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode character u'\xe9' in position 0: ordinal not in range(128)
Failed to execute (Script).
import codecs import sys aninput = sys.argv[1].decode(sys.getfilesystemencoding()) textfile = codecs.open("testfile","w","utf-8") textfile.write(aninput) textfile.close()
Does the following script not work for you? It works fine for me, and if I remove the decode, I get the same error as you.import codecs import sys aninput = sys.argv[1].decode(sys.getfilesystemencoding()) textfile = codecs.open("testfile","w","utf-8") textfile.write(aninput) textfile.close()
Got it to work! 🙂 THANXS
the reason it would'nt work was because I was adding the following line:
"arcpy.AddMessage(str(aninput))"