相关疑难解决方法(0)

使用CSV Django模块以通用换行模式打开文件

我试图访问model.filefieldDjango 中使用该模块解析Python中的CSV文件csv.它在Windows上工作,但在Mac上它给了我这个:

Exception Type: Error

Exception Value: new-line character seen in unquoted field - do you need to open the file in universal-newline mode?
Run Code Online (Sandbox Code Playgroud)

这是代码:

myfile = customerbulk.objects.all()[0].fileup

mydata = csv.reader(myfile)
    for email,mobile,name,civilid in mydata:
        print email,mobile,name,civilid
Run Code Online (Sandbox Code Playgroud)

csv django macos newline python-2.x

86
推荐指数
1
解决办法
7万
查看次数

Python解析csv文件 - 用冒号替换逗号

我怀疑这是一个常见的问题,但我似乎找不到答案.我试图从csv文件中删除所有逗号并用冒号替换它们.我通常会使用sed或vi,但我需要使用纯粹的python实现.这是我到目前为止提出的:

import csv

with open("temp.csv", mode="rU") as infile:
    reader = csv.reader(infile, dialect="excel")    
    with open("temp2.txt", mode="w") as outfile:
        writer = csv.writer(outfile)
        for rows in reader:
            for parsed_item in rows:
                parsed_item = rows.replace(',', ':') # I can't do this with a list!
                writer.writerow(parsed_item)
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我解决这个问题吗?在此先感谢您的帮助.

python csv parsing

10
推荐指数
2
解决办法
2万
查看次数

标签 统计

csv ×2

django ×1

macos ×1

newline ×1

parsing ×1

python ×1

python-2.x ×1