0

I have a django form which accepts a text file, which I process directly in a view method. It has worked fine, until someone recently tried uploading a text file created on a Mac, which has different newlines (\r), and the function treated the entire file as a single line. I was under the impression that python deals with newlines in a universal fashion - any ideas what I could do to fix this? I'm running django 1.5, python 2.7 on a Linux server.

The following is a snippet of the code used:

def get_students(self, request, form):
    for line_num, line in enumerate(form.files['bulk_file']):
        ...

def post(self, request, *args, **kwargs):
    credit = Credit.objects.get(id=self.kwargs['pk'])
    form_class = self.get_form_class()
    form = form_class(request.POST, request.FILES, credit=credit)
    if form.is_valid():
        for student in self.get_students(request, form):
        ....
askvictor
  • 3,621
  • 4
  • 32
  • 45
  • 1
    Please show the code you use to process this file. Are you using the `csv` module? It should handle it correctly. – Cfreak Jun 02 '15 at 03:24
  • @Cfreak - added code, and updated to specify that it's just a plain text file (It's a one-column CSV, so it's not really a CSV I guess). – askvictor Jun 02 '15 at 03:34

0 Answers0