0

This is just about my first day using Python, and I'm trying to remove any accents in a set of arguments that I have. I know how to convert a given string to unicode:

myfoo = u'àà'

But how do I convert the arguments of a function into unicode? My attempt was to create a function that began as follows:

def newfunction(args):
    myunicode = u'args['arg1']'
    convertedarg1 = unicodedata.normalize('NFD', my_unicode).encode('ascii', 'ignore')

But of course, this "converts" the string "args['arg1']" instead of the actual value given to arg1. I would like to fix the first step such that if arg1=café, convertedarg1 = cafe.

I hope that makes some sense.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
  • 1
    Why do you not use up-to-date Python version? – mkrieger1 Oct 28 '20 at 22:19
  • I wish I could, but I'm bound to 2.7 by the computers at work :( – Doomsday Oct 28 '20 at 22:20
  • Is your text editor using UTF-8? Do you have this at the beginning of the source file? `# -*- coding: utf-8 -*-`? – Rick James Oct 28 '20 at 22:44
  • Which OS? In Windows, try `sys.argv[1].decode('cp1250')` (Use your ACP instead of `1250`). ACP obtained from `REG QUERY "HKLM\SYSTEM\CurrentControlSet\Control\Nls\CodePage" -v ACP`. – JosefZ Oct 28 '20 at 22:59
  • @mkrieger1 Yes, it did! Ultimately, I needed to write dummy1 = args['arg1'] dummy2 = unicode(dummy1, "utf-8") convertedarg1 = unicodedata.normalize('NFD', dummy2).encode('ascii', 'ignore') Thank you so much! – Doomsday Oct 28 '20 at 23:03

0 Answers0