tags:

views:

97

answers:

2

What am I doing wrong to get this error?

    replacements = {}
    replacements["**"] = ("<strong>", "</strong>")
    replacements["__"] = ("<em>", "</em>")
    replacements["--"] = ("<blink>", "</blink>")
    replacements["=="] = ("<marquee>", "</marquee>")
    replacements["@@"] = ("<code>", "</code>")

    for delimiter, (open_tag, close_tag) in replacements: # error here
        message = self.replaceFormatting(delimiter, message, open_tag, close_tag); 

The error:

Traceback (most recent call last):
File "", line 1, in for shit, (a, b) in replacements: ValueError: need more than 1 value to unpack

All the values tuples have two values. Right?

+7  A: 

It should be:

for delimiter, (open_tag, close_tag) in replacements.iteritems(): # or .items() in py3k
SilentGhost
arg.. beat me to it
YuppieNetworking
That he did. General question though, why not:....for delimiter in replacements: open_tag, close_tag = replacements[delimiter]....
qor72
@qor721: unpacking earlier is more efficient and idiomatic, I'd say
SilentGhost
+2  A: 

I think you need to call .items() like the third example in this link

for delimiter, (open_tag, close_tag) in replacements.items(): # error here
    message = self.replaceFormatting(delimiter, message, open_tag, close_tag)
YuppieNetworking