python – ValueError:没有足够的值来解压缩(预期11,得1)

我写了一个系统自动化脚本,但是我收到了标题中描述的错误.我下面的代码是脚本的相关部分.问题是什么?

import csv
import os

DIR = "C:/Users/Administrator/Desktop/key_list.csv"

def Customer_List(csv):
    customer = open(DIR)
        for line in customer:
            row = []
            (row['MEM_ID'],
             row['MEM_SQ'],
             row['X_AUTH_USER'],
             row['X_AUTH_KEY'],
             row['X_STORAGE_URL'],
             row['ACCESSKEY'],
             row['ACCESSKEYID'],
             row['ACCESSKEY1'],
             row['ACCESSKEYID1'],
             row['ACCESSKEY2'],
             row['ACCESSKEYID2'])=line.split()
            if csv == row['MEM_ID']:
                customer.close()
                return(row)
            else:
                print ("Not search for ID")
                return([])

id_input = input("Please input the Customer ID(Email): ")
result = Customer_List(id_input)

if result:
    print ("iD:    " + id['MEM_ID']

最佳答案 对于线

line.split()

你在分裂什么?看起来像CSV,所以试试吧

line.split(',')

例:

"one,two,three".split()  # returns one element ["one,two,three"]
"one,two,three".split(',')  # returns three elements ["one", "two", "three"]

编辑:正如@ TigerhawkT3所提到的,最好使用CSV模块.令人难以置信的快速简便的方法here.

点赞