Django python escape \n characters
===

In the following function, i upload a file from a template and pass it to the following function.But the data gets crippled if there is a \n or \t(`This is a tab separated file`).

1.If there is a \n or some special characters it stores the data in the next row.How to avoid this .

2.data is not None or data != "" still stores a null value


    def save_csv(csv_file,cnt):
     ret = 1
     arr = []
     try:
      #wb = xlrd.open_workbook(str(csv_file),encoding_override="cp1252")   ##To specify UTF8-encoding
      #wb.sheet_names()
      #sh =  wb.sheet_by_index(0)
      #num_of_rows = sh.nrows
      #num_of_cols = sh.ncols
      flag = 0
      f = open(csv_file)
      for l in f:
         if flag == 0:
            flag += 1
            continue
         parts = l.split("\t")
         logging.debug(parts)
         logging.debug("===================================")
         counter = 1
         if(len(parts) > 6):
            ret = 2
            for obj in arr:
               obj.delete()
            return ret
         else:
            taggeddata = Taggeddata()
            for data in parts:
               data = str(data.strip())
               if counter == 1 and (data is not None or data != ""):
                  taggeddata.field1 = data
               elif counter == 2 and (data is not None or data != ""):
                  taggeddata.field2 = data
               elif counter == 3 and (data is not None or data != ""):
                  taggeddata.field3 = data
               elif counter == 4 and (data is not None or data != ""):
                  taggeddata.field4 = data
               elif counter == 5 and (data is not None or data != ""):
                  taggeddata.field5 = data
               elif counter == 6 and (data is not None or data != ""):
                  taggeddata.field6 = data
               counter += 1
            taggeddata.content_id = cnt.id
            taggeddata.save()
            arr.append(taggeddata)
      return ret
    except:
      write_exception("Error while processing data and storing")