Python二维数字列表到csv

时间:2017-11-08 14:09:03

标签: python python-3.x csv

我正在寻找将2D列表转换为包含每个点的坐标(xyz)的csv文件的最佳方法。

2D列表具有以下格式:

[mysqld]
default_password_lifetime=0
max_allowed_packet = 1G  
net_read_timeout = 240
net_write_timeout = 1800

innodb_buffer_pool_size = 8G
innodb_flush_log_at_trx_commit = 2

# Add absurd timeout
wait_timeout = 172800
interactive_timeout = 172800

[mysqldump]
max_allowed_packet = 1G

使用:

               $nome = $_GET['nome'];
            //Searching the nome in the database
                    $req = $dbh->prepare("SELECT COUNT(*) AS anzahl FROM user WHERE Benutzername = :nome");
            //Counts the rows with the given nom
                    $req->bindParam(':nome', $nome, PDO::PARAM_STR);
                    $req->execute();
                    $result = $req->fetch();
                    if ($result[0] > 0) {
            //already exists - A row was found 
                        echo "Already exists";
                    }
                    else {
            //not existing - There was no row with that username
                     "Your Insertquery, use $req2 here"
                    }

将返回一个转置的对象列表,无法轻松绘制。

如果有人能提出解决方法,我会很高兴。

1 个答案:

答案 0 :(得分:0)

使用zip()可以做你想要的。

with open("output.csv", "w") as csvfile:
    writer = csv.writer(csvfile)
    writer.writerows( zip(x, y, z) )

csv看起来像

x1, y1, z1
x2, y2, z2
x3, y3, z3
...