2014-10-03 86 views
0
line = line.strip() 
rsid, chromosome, position, genotype = line.split(",") 

它给我一个值错误说这个错误是什么意思? Python的错误

ValueError: Need more than one value to unpack 

我该如何解决这个问题?

+1

这意味着您的行很可能是*空*。 – 2014-10-03 15:19:28

+0

这意味着line.split()只返回一个值。所以它的空白 – 2014-10-03 15:20:16

+0

'print(line.spit(','))'会告诉你这个问题。 – tdelaney 2014-10-03 15:22:50

回答

0

错误告诉你只有一个line.split(',')返回的列表中的字符串。这意味着该字符串中没有逗号,并且分割返回了该字符串,但在列表中。

通常情况下,这意味着你的字符串是空的,开始:

>>> 'string with no commas'.split(',') 
['string with no commas'] 
>>> ''.split(',') 
[''] 

您可以轻松地跳过空行:

line = line.strip() 
if not line: 
    continue # next iteration of the loop 
rsid, chromosome, position, genotype = line.split(",") 

你可能想看看在csv module而不是分裂文件行自己。