help me debug my "word capitalizer" script
Terry Reedy
tjreedy at udel.edu
Wed Aug 22 13:40:56 EDT 2012
On 8/22/2012 10:46 AM, Rebelo wrote:
>> Is it possible to make this script look at a word, see if its first
>> character is capitalized, if capitalized then skip that word.
Unicode has two 'capital' concepts: 'uppercase' and 'titlecase'. They
are the same for latin chars but not for all alphabets.
>> I don't wan to use regex? Do I need it?
No. It may or may not be easier.
> change:
> words[i] = word.capitalize()
>
> into:
> if word != word.upper() :
> words[i] = word.capitalize()
Still buggy
>>> s = 'CamelCase'
>>> if s != s.upper(): s = s.capitalize()
>>> s
'Camelcase'
use "if not word[0].isupper:..."
or "if word[0].islower
This will still .capitalize() 'weirdWord' to 'Weirdword'.
If you do not want that, only change the first letter.
>>> s = 'weirdWord'
>>> if s[0].islower(): s = s[0].upper()+s[1:]
>>> s
'WeirdWord'
--
Terry Jan Reedy
More information about the Python-list
mailing list