0

I am very new to python and my first task is to check older code (not mine!) to convert it according to pep8.

I have the following code block and I should change raise ValueError to raise ValueError("Message"). How has the syntax of the message to look like, something like 'could not find %c in %s' % (ch,str)?

def sort_key(self, string):

    collation_elements = []

    lookup_key = [ord(ch) for ch in string]
    while lookup_key:
        value, lookup_key = self.table.find_prefix(lookup_key)
        if not value:
            # @@@
            raise ValueError, map(hex, lookup_key)
        collation_elements.extend(value)

    sort_key = []

    for level in range(4):
        if level:
            sort_key.append(0)  # level separator
        for element in collation_elements:
            ce_l = int(element[1][level], 16)
            if ce_l:
                sort_key.append(ce_l)

    return tuple(sort_key)
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Til Hund
  • 1,543
  • 5
  • 21
  • 37
  • 4
    That already *has* a message; all you need to do is change the syntax from `raise Exception, msg` to `raise Exception(msg)` – jonrsharpe May 06 '15 at 09:17
  • possible duplicate of [How to fix: W602 deprecated form of raising exception](http://stackoverflow.com/questions/11991637/how-to-fix-w602-deprecated-form-of-raising-exception) – jonrsharpe May 06 '15 at 09:21
  • Ups, thank you for pointing it out to me, jonrsharpe. I previously had it in brackets but within "" too. – Til Hund May 06 '15 at 11:14

0 Answers0