CSV文件创建问题 [英] CSV file creation issue

查看:340
本文介绍了CSV文件创建问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这行代码从python脚本创建一个csv文件:

I'm creating a csv file from a python script with this lines:

def createFile():
    logfile = csv.writer(open('logfile.csv', 'wb'), dialect='excel')
    formater = zip(dates, hours, threadids, loglevels, errorcodes, errormessage)
    for i in formater:
        logfile.writerow(i)

使用Excel打开文件,因为它打开一个列中的整个文本。这是csv的一行如何看起来像:

And everything works fine until I open the file with Excel because it opens the whole text in one column. This is how one row from the csv looks like:

4/29/12,22:44:32:865 EDT,0000004b,A,CHFW0019I,The Transport Channel Service has started chain chain_308.

有没有什么办法打开文件拆分的列如何应该是?
谨慎。

Is there any way to open the file splitted in columns how it should be? Regards.

推荐答案

我在 foo.csv

I saved the following in foo.csv and it opens fine in Excel.

4/29/12,22:44:32:865 EDT,0000004b,A,CHFW0019I,The Transport Channel Service has started chain chain_308.
4/29/12,22:44:32:865 EDT,0000004b,A,CHFW0019I,The Transport Channel Service has started chain chain_308.
4/29/12,22:44:32:865 EDT,0000004b,A,CHFW0019I,The Transport Channel Service has started chain chain_308.
4/29/12,22:44:32:865 EDT,0000004b,A,CHFW0019I,The Transport Channel Service has started chain chain_308.
4/29/12,22:44:32:865 EDT,0000004b,A,CHFW0019I,The Transport Channel Service has started chain chain_308.

您可能想要检查您是否在区域设置中使用以下选项之一配置了正确的列表分隔符:

You might want to check if you have the right list separator configured in your regional settings using one of the following:


  1. Windows开始按钮>控制面板>区域和语言选项>区域选项>自定义>列表分隔符。

  2. Windows开始按钮>控制面板>区域和语言选项>格式>其他设置>列表分隔符。

请注意,使用命令 intl.cpl ,即按下Windows + R按钮并输入 intl.cpl

Note that you can also launch 'Regional and Language Options' with the command intl.cpl, i.e. press Windows + R button and enter intl.cpl and press the 'OK' button.

这篇关于CSV文件创建问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆