|
|
发表于 2019-8-18 21:47:21
|
显示全部楼层
ValueError: not enough values to unpack (expected 2, got 1)
ValueError:值不足,无法解包(应为2,得到1)
另一种得到同一种错误的方法:
>>> (a, b) = [1]
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
(a, b) = [1]
ValueError: not enough values to unpack (expected 2, got 1)
很明显,左边的列表提供的值不能满足右边元组的所有元素
>>> dir(str)
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
>>> help(str.split)
Help on method_descriptor:
split(self, /, sep=None, maxsplit=-1)
Return a list of the words in the string, using sep as the delimiter string.
sep
The delimiter according which to split the string.
None (the default value) means split according to any whitespace,
and discard empty strings from the result.
maxsplit
Maximum number of splits to do.
-1 (the default value) means no limit.
翻译:
拆分(self,/,sep=none,maxsplit=-1)
返回字符串中的单词列表,使用sep作为分隔符字符串。
九月
分隔字符串的分隔符。
无(默认值)表示根据任何空白分割,
并放弃结果中的空字符串。
最大分割
要执行的最大拆分数。
-1(默认值)表示无限制。
错误显示传递给元组的值不够。
你要将字符串分成两份应该是:
split(':', 2)
或者
split(':')
因为每个字符串只有一个冒号。 |
|