Open the file in universal newline mode using the Django CSV module

I am trying to access model.filefield in Django to parse a CSV file in Python using the csv module. It works on Windows, but on Mac it gave me the following:

 Exception Type: Error Exception Value: new-line character seen in unquoted field - do you need to open the file in universal-newline mode? 

This is the code:

 myfile = customerbulk.objects.all()[0].fileup mydata = csv.reader(myfile) for email,mobile,name,civilid in mydata: print email,mobile,name,civilid 
+85
python django newline csv macos
Jul 17 2018-11-17T00:
source share
1 answer

Finally, I found a solution:

 mypath = customerbulk.objects.get(pk=1).fileup.path o = open(mypath,'rU') mydata = csv.reader(o) 
+146
Jul 18 2018-11-21T00:
source share



All Articles