Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:help': 0.07; '"if': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:script': 0.09; 'terry': 0.09; 'buggy': 0.16; 'easier.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'wrote:': 0.17; 'skip': 0.17; 'unicode': 0.17; 'jan': 0.18; '>>>': 0.18; 'script': 0.24; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'header:X -Complaints-To:1': 0.28; 'letter.': 0.29; 'character': 0.29; 'word.': 0.33; 'to:addr:python-list': 0.33; 'that,': 0.34; 'received:org': 0.36; 'but': 0.36; 'subject:" ': 0.36; 'possible': 0.37; 'two': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'first': 0.61; 'latin': 0.84; 'received:fios.verizon.net': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: help me debug my "word capitalizer" script Date: Wed, 22 Aug 2012 13:40:56 -0400 References: <035e81d4-8e43-40fd-a0fa-c60b28f0703a@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-173-75-251-66.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0 In-Reply-To: <035e81d4-8e43-40fd-a0fa-c60b28f0703a@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1345657293 news.xs4all.nl 6864 [2001:888:2000:d::a6]:33731 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:27662 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