calling upper() on a string, not working?
Bruno Desthuilliers
bdesth.quelquechose at free.quelquepart.fr
Wed May 17 08:29:45 EDT 2006
John Salerno a écrit :
> Bruno Desthuilliers wrote:
>
>>> def encrypt_quote(original):
>>
>> # Since it's here that we define that the new letters
>> # will be uppercase only, it's our responsability
>> # to handle any related conditions and problems
>> # The other functions shouldn't have to even know this.
>> original = original.upper()
>
>
>>> def filter_letters(original):
>>
>> # here, we *dont* have to do anything else than filtering
>> # upper/lower case is *not* our problem.
>>
>>> return ''.join(set(original) - PUNCT_SPACE_SET)
>
>
> Thanks, I was wondering if it only needed to be done in a single place
> like that.
It's always better to do something in a single place - you may here of
this as the DRY (Dont Repeat Yourself) or SPOT (Single Point Of
Transformation) rule.
The way you wrote it, part of encrypt_quote's responsability and
knowldege was leaking into filter_letters. This is a Bad Thing(tm), and
should be avoided by any mean.
More information about the Python-list
mailing list