calling upper() on a string, not working?

Scott David Daniels scott.daniels at acm.org
Wed May 17 01:00:07 CEST 2006


John Salerno wrote:
<Some code, with a request to get case working.>
Others have shown you where the bug was.

You might want to change encrypt_quote like this:

XXX> def encrypt_quote(original):
   def encrypt_quote(original, casemap=True):
XXX>  original_letters = filter_letters(original)
       if casemap:
           original_letters = filter_letters(original.upper())
       else:
           original_letters = filter_letters(original)
XXX>  new_letters = list(string.ascii_uppercase)
       if len(original_letters) > 26:
           new_letters = list(string.ascii_uppercase + 
string.ascii_lowercase)
           casemap = False
       else:
           new_letters = list(string.ascii_uppercase)
>     while True:
>         random.shuffle(new_letters)
>         trans_letters = ''.join(new_letters)[:len(original_letters)]
>         if test_code(original_letters, trans_letters):
XXX>          trans_table = string.maketrans(original_letters, 
trans_letters)
               if casemap:
                   trans_table = string.maketrans(
                         original_letters + original_letters.lower(),
                         trans_letters + trans_letters.lower())
               else:
                   trans_table = string.maketrans(original_letters, 
trans_letters)
>             break
>     return original.translate(trans_table)


--Scott David Daniels
scott.daniels at acm.org



More information about the Python-list mailing list