ValueError:解压缩处理csv文件的值太多

时间:2016-10-31 06:13:55

标签: python file csv

我有以下exactly one root element

$ python test_tiny.py 
Traceback (most recent call last):
  File "test_tiny.py", line 48, in <module>
    tail_to_numbers = {ftail: fnum for fnum, ftail in csv_reader}
  File "test_tiny.py", line 48, in <dictcomp>
    tail_to_numbers = {ftail: fnum for fnum, ftail in csv_reader}
ValueError: too many values to unpack

我收到了这个错误:

$ head -5 tiny_stat.csv 
1,002qtwH.txt,bed,47%,dog,55%
2,0066Z9W.txt,person,57%
3,0082B22.txt,
4,008BdUz.txt,train,68%
5,00c5Zm8.txt,train,61%,car,59%,car,58%

tiny_stat.csv的前5行如下所示:

class Connection {

    public static function make() {
        try {
                return $pdo = new PDO('mysql:host=127.0.0.1;dbname=mytodo', 'root', 'mysql');
            } catch(PDOException $e) {
                die($e->getMessage().' DB Could not find');
            }
    }

在tiny_graph.csv中,我想创建这样的行: 1,80

其中1和80是打开的文本文件的文件编号,我从tiny_stat.csv中找到它们的编号。

1 个答案:

答案 0 :(得分:1)

更改{ftail: fnum for fnum, ftail in csv_reader}

{row[1]: row[0] for row in csv_reader}