New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Certain diacritical marks can and should be capitalized... e.g. ü --> Ü #58792
Comments
BUGS: certain diacritical marks can and should be capitalized... def myUpper(inString):
return inString.upper().replace('à', 'À').replace('ä', 'Ä').replace('è', 'È').replace('é', 'É').replace('ö', 'Ö').replace('ü', 'Ü')
def myLower(inString):
return inString.lower().replace('À', 'à').replace('Ä', 'ä').replace('È', 'è').replace('É', 'é').replace('Ö', 'ö').replace('Ü', 'ü')
def myTitle(inString): # WARNING: converts all whitespace to a single space
returnValue = []
for theWord in inString.split():
returnValue.append(myUpper(theWord[:1]) + myLower(theWord[1:]))
return ' '.join(returnValue) |
It works fine if you use unicode. |
On Apr 15, 2012, at 4:43 PM, R. David Murray wrote:
What does it mean in this context to "use unicode"?? Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> lusai = u'lüsai'
Unsupported characters in input
>>> lusai = 'lüsai'
Unsupported characters in input
>>> print "ŠČŽ"
Unsupported characters in input =============================================== print '==========' import sys # sys.version_info = sys.version_info(major=2, minor=7, micro=1, releaselevel='final', serial=0)
print 'sys.version_info = {}.{}.{} {} {}'.format(sys.version_info[0], sys.version_info[1], sys.version_info[2], sys.version_info[3], sys.version_info[4])
import commands, os
print 'os.name = {}'.format(os.name)
print 'os.uname = {}'.format(os.uname()) print '==========' def myUpper(inString):
return inString.upper().replace('à', 'À').replace('ä', 'Ä').replace('è', 'È').replace('é', 'É').replace('ö', 'Ö').replace('ü', 'Ü').replace('ẞ', 'ß')
def myLower(inString):
return inString.lower().replace('À', 'à').replace('Ä', 'ä').replace('È', 'è').replace('É', 'é').replace('Ö', 'ö').replace('Ü', 'ü').replace('ß', 'ẞ')
def myTitle(inString):
returnValue = []
for theWord in inString.split():
returnValue.append(myUpper(theWord[:1]) + myLower(theWord[1:]))
return ' '.join(returnValue)
def formatted(inValue, inSep = ' '):
s = str(inValue)
print ' s={}{}su={}{}sl={}{}st={}...'.format(s, inSep, s.upper(), inSep, s.lower(), inSep, s.title())
print ' s={}{}mu={}{}ml={}{}mt={}...'.format(s, inSep, myUpper(s), inSep, myLower(s), inSep, myTitle(s))
u = unicode(inValue, 'utf8')
try:
print ' u={}{}uu={}{}ul={}{}ut={}...'.format(u, inSep, u.upper(), inSep, u.lower(), inSep, u.title())
except:
print "=== Exception thrown trying to print unicode({}, 'utf8')".format(repr(s))
kolnUpperUnspecified = str('KÖLN')
kolnUpperAsString = str('KÖLN')
kolnUpperAsUnicode = unicode('KÖLN', 'utf8')
kolnLowerUnspecified = str('köln')
kolnLowerAsString = str('köln')
kolnLowerAsUnicode = unicode('köln', 'utf8')
formatted(kolnUpperUnspecified)
formatted(kolnUpperAsString)
try:
formatted(kolnUpperAsUnicode)
except:
pass
formatted(kolnLowerUnspecified)
formatted(kolnLowerAsString)
try:
formatted(kolnLowerAsUnicode)
except:
pass
formatted('Ötto Clauß lives in the hamlet of Lüsai in the village of Lü in the valley of Val Müstair in the Canton of Graubünden', '\n')
formatted('ZÜRICH is the largest city in Switzerland and the geographic center of the country is in Älggi-Alp which can be reached via the Lötschberg Tunnel', '\n')
formatted('20% of Swiss people speak Französisch but only 0.5% speak Rätoromanisch', '\n')
formatted('LÜSAI, lüsai, München, Neuchâtel, Ny-Ålesund, Tromsø, ZÜRICH', '\n') print """BUGS: certain diacritical marks can and should be capitalized... |
In addition to R. David's remark, it also works fine in a German locale. In general, you cannot know whether the byte '\xe4' denotes 'ä' or some other letter. For example, in KOI8-R, it denotes Д, instead, which already is an upper-case letter. So either do setlocale at the start of your program, or (better) switch to Unicode strings. Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print u'ä'.upper()
Ä |
Or you can port your program to Python 3 to avoid such issues :-) |
Indeed, this type of confusion is a large part of the motivation behind Python3. You might try posting to the python-list mailing list asking for help if for some reason you are required to use python2 for your program. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: