Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.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.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'example:': 0.03; 'collier': 0.09; 'comment,': 0.09; 'function,': 0.09; 'tackle': 0.09; 'worse': 0.09; 'url:blog': 0.10; 'python': 0.11; 'def': 0.12; '3.3,': 0.16; 'dangerous,': 0.16; 'letters.': 0.16; 'lowercase': 0.16; 'redundant': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'uppercase': 0.16; 'version?': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'users.': 0.18; 'command': 0.22; 'example': 0.22; 'shell': 0.22; 'header:User-Agent:1': 0.23; 'subject:Code': 0.24; 'header:In-Reply-To:1': 0.27; 'to:2**1': 0.27; 'function': 0.29; 'skip:p 30': 0.29; "doesn't": 0.30; 'code': 0.31; 'comments': 0.31; 'received:10.0.0': 0.31; 'reply.': 0.31; 'that.': 0.31; 'catching': 0.31; "d'aprano": 0.31; 'helpful.': 0.31; 'steven': 0.31; 'figure': 0.32; 'skip:c 30': 0.32; 'run': 0.32; 'fri,': 0.33; 'comment': 0.34; "can't": 0.35; 'something': 0.35; 'convert': 0.35; 'german': 0.35; 'johnson': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'version': 0.36; 'introducing': 0.36; 'useful': 0.36; 'thanks': 0.36; 'received:10.0': 0.36; 'should': 0.36; 'two': 0.37; 'received:10': 0.37; 'being': 0.38; 'thank': 0.38; 'e.g.': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'anything': 0.39; 'url:01': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'even': 0.60; 'eventually': 0.60; 'most': 0.60; 'tell': 0.60; 'hope': 0.61; 'making': 0.63; 'become': 0.64; 'different': 0.65; 'account': 0.65; 'herr': 0.68; 'url:info': 0.73; 'jul': 0.74; 'url:2011': 0.75; 'skip:$ 10': 0.81; 'amazed': 0.84; 'hard.': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=nsuR7rN5dDwWaz6fjien5luhxuYLzwuJ+H7wjYY4qRk=; b=qlHNXUZeFZlm/w+y6BTYeRp+Kju/b4s3oStoS+NUwQP0ggWUSSEJHLTe75u7MEh5RI AM2BnqAk7t6spT+1RbNZUJCnoE1h4rDxF/U1Uc221Pkfo4SMM4eDacYk+Pknw4IyFEMH G05jDi/cZQ/FiUNpOWAmS8RgqRNu/61ggfv7C1F0F7Gduw+LBcCKd960pb0l3/JTWZMY deVCI3V4cJDtiX+4Lk4E5b2zGwHiHwNgFcFsXOgY9oMPPVeTPbHnw30Nutmm7xQQZZrN U4/Kyv6X0DskWJ45hf1opZiiUibu/pOmEWYYKGzGZv4u/2yv3sgLnVa6WW4REPITaPZQ OvYQ== X-Received: by 10.42.172.194 with SMTP id o2mr12340818icz.41.1374271726202; Fri, 19 Jul 2013 15:08:46 -0700 (PDT) Date: Fri, 19 Jul 2013 18:08:43 -0400 From: Devyn Collier Johnson User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130623 Thunderbird/17.0.7 MIME-Version: 1.0 To: Steven D'Aprano , Python Mailing List Subject: Re: Share Code Tips References: <51e97e6e$0$29971$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <51e97e6e$0$29971$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 69 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1374271729 news.xs4all.nl 15886 [2001:888:2000:d::a6]:45317 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50923 On 07/19/2013 01:59 PM, Steven D'Aprano wrote: > On Fri, 19 Jul 2013 09:51:23 -0400, Devyn Collier Johnson wrote: > >> def KDE_VERSION(): >> print(subprocess.getoutput('kded4 --version | awk -F: >> \'NR == 2 {print $2}\'').strip()) ##Get KDE version## > I run KDE 3, and the above does not work for me. > > *half a wink* > > By the way, a comment that doesn't tell you anything that you don't > already know is worse than useless. The function is called "KDE_VERSION, > what else would it do other than return the KDE version? > > > x += 1 # add 1 to x > > Worse than just being useless, redundant comments are dangerous, because > as a general rule comments that don't say anything useful eventually > become out-of-date, they become *inaccurate* rather than *redundant*, and > that's worse than being useless. > > >> Need a case-insensitive if-statement? Check this out: >> >> if 'YOUR_STRING'.lower() in SOMEVAR.lower(): > Case-insensitivity is very hard. Take German for example: > > STRASSE <-> straße > > Or Turkish: > > İ <-> i > I <-> ı > > > In Python 3.3, you should use casefold rather than lowercase or uppercase: > > if some_string.casefold() in another_string.casefold(): ... > > > but even that can't always take into account localised rules, e.g. in > German, you should not convert SS to ß for placenames or person names, so > for example Herr Meißner and Herr Meissner are two different people. This > is one of the motivating reasons for introducing the uppercase ß. > > http://opentype.info/blog/2011/01/24/capital-sharp-s/ > > > Steven, thanks for your interesting comments. Your emails are very insightful. As for the KDE function, I should fix that. Thank you for catching that. Notice that the shell command in the function is "kded4". That would only check the version for the KDE4 series. The function will only work for KDE4 users. As for the comment, you would be amazed with the people that ask me "what does this do?". These people are redundant (^u^). As for the case-insensitive if-statements, most code uses Latin letters. Making a case-insensitive-international if-statement would be interesting. I can tackle that later. For now, I only wanted to take care of Latin letters. I hope to figure something out for all characters. Thank you for your reply. I found it to be very helpful. Mahalo, DCJ