我试图访问Django中的model.filefield
,以使用csv
模块在Python中解析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?
这是代码:
myfile = customerbulk.objects.all()[0].fileup
mydata = csv.reader(myfile)
for email,mobile,name,civilid in mydata:
print email,mobile,name,civilid
我终于找到了解决办法:
mypath = customerbulk.objects.get(pk=1).fileup.path
o = open(mypath,'rU')
mydata = csv.reader(o)