Share Code Tips

Devyn Collier Johnson devyncjohnson at gmail.com
Fri Jul 19 18:08:43 EDT 2013


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



More information about the Python-list mailing list