0

Using the following code:

def printformatted(statuses):
    for status in statuses:
        statusid, statussummary = status.split(",",1)
        print "\nSnapshot id: %s" % statusid
        print   "Summary:     %s" % statussummary
    print

printformatted("1,Some summary") gives me the error ValueError: need more than 1 value to unpack, whereas printformatted(["1,Some summary"]) does not. Why?

4

1 回答 1

2

In the first case, you're passing a string, so for status in statuses iterates over the string, character by character, which is not what you want.

In the second case, you're passing a list, so for status in statuses iterates over its elements, first element being "1,Some summary".

于 2013-03-30T15:22:15.920 回答