Special characters in city.setName()

Fierabras

Emperor
Joined
Dec 26, 2006
Messages
1,120
I'm trying to set the name of a city through Python like:

Code:
city.setName("Tenochtitl&x225;n", False)

but in the dll the special characters are removed again:

Code:
void CvCity::setName(const wchar* szNewValue, bool bFound)
{
	CvWString szName(szNewValue);
	gDLL->stripSpecialCharacters(szName);

and I end up with the name "Tenochtitlx225;n" and not "Tenochtitlán"

Is there a way around this without making a new dll? Python will only accept ASCII and the only way I got it working is by retrieving the city name from XML, parsed through CyTranslator(), which does work :confused:
 
Nevermind. Looks like I got it now. I added this in my Python file

Code:
import sys
sys.setdefaultencoding('iso-8859-1')

to change the encoding from the default ascii to the larger character set iso-8859-1. After that

Code:
city.setName("Tenochtitlán", False)

works fine...
 
I was going to instead suggest using a Unicode string by placing a u in front of the string literal:

Code:
city.setName(u"Tenochtitlán", False)

You can then use Unicode escapes if you want: \uXXXX.
 
Unicode support is built-in to Python. Adding a u in front of a string makes it a Unicode string. It's possible that to enter the accented characters directly into the Python file itself may require changing the encoding, as you need to tell the Python file-loading system how to read files.

If you stick to the Unicode \uXXXX escapes, no other steps are required as the file is still ASCII-based.
 
Top Bottom