Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #27662
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: help me debug my "word capitalizer" script |
| Date | 2012-08-22 13:40 -0400 |
| References | (1 earlier) <CAEtwbM0PwcSb6v5MZ=Dr3s9TVFoXzCOywd=JfWFfBUcM-RFLcQ@mail.gmail.com> <CAPTjJmr7JqsDx6ypjVODTvy315fFYZacNgns60QXmM+zJ5p+Xw@mail.gmail.com> <CAEtwbM2MZ9D_dwv0EYXF8h5G=ucOjVm33Y3Z+E=aMY1fr17Nxw@mail.gmail.com> <mailman.3647.1345640467.4697.python-list@python.org> <035e81d4-8e43-40fd-a0fa-c60b28f0703a@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3671.1345657293.4697.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: help me debug my "word capitalizer" script Santosh Kumar <sntshkmr60@gmail.com> - 2012-08-22 18:30 +0530
Re: help me debug my "word capitalizer" script Rebelo <puntabluda@gmail.com> - 2012-08-22 07:46 -0700
Re: help me debug my "word capitalizer" script Terry Reedy <tjreedy@udel.edu> - 2012-08-22 13:40 -0400
Re: help me debug my "word capitalizer" script Rebelo <puntabluda@gmail.com> - 2012-08-22 07:46 -0700
csiph-web