Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 知道如何将表格输出到CSV文件吗?_Python_Csv - Fatal编程技术网

Python 知道如何将表格输出到CSV文件吗?

Python 知道如何将表格输出到CSV文件吗?,python,csv,Python,Csv,我只想弄清楚如何根据标题将表格结果写入CSV文件,因为当我在CSV中写入表格结果时,使用python 2.7,所有结果仅在一列中。panda框架对此有必要吗 from tabulate import tabulate class Finder: def print_extensions(self): c = Chrome(self.os) print tabulate(c.extensions(), headers="keys") if sel

我只想弄清楚如何根据标题将表格结果写入CSV文件,因为当我在CSV中写入表格结果时,使用python 2.7,所有结果仅在一列中。panda框架对此有必要吗

from tabulate import tabulate
class Finder:

def print_extensions(self):
        c = Chrome(self.os)
        print tabulate(c.extensions(), headers="keys")

        if self.os == WinBrowsers: 
            i = InternetExplorer(self.os)
            content2 = tabulate(i.extensions(), headers="keys")
            text_file=open("output.csv","w")
            text_file.write(content2)
            text_file.close()
以下是我的控制台的示例输出:

version       name                           id
------------  -----------------------------  --------------------------------
0.10          Slides                         aapocclcgogkmnckokdopfmhonfmgoek
0.10          Docs                           aohghmighlieiainnegkcijnfilokake


path                                                                             name                                           id
-------------------------------------------------------------------------------  ---------------------------------------------  --------------------------------------
C:\Windows\SysWOW64\ieframe.dll                                                  Microsoft Url Search Hook                      {CFBFAE00-17A6-11D0-99CB-00C04FD64497}
C:\Program Files\Trend Micro\TMIDS\bhoDirectPass32.dll                           Password Manager ToolBar                       {97EE74D2-C351-4ECE-B75A-8CD36FAE3661}
没有必要用熊猫来做这个

标准库已经提供了一个模块

该模块中的有一个简单明了的示例,说明如何写出csv

根据您的示例对其进行调整,可以得到:

with open('output.csv', 'w') as csvfile:
    writer = csv.writer(csvfile)
    writer.writerow(content2)