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)