0

Okay, so I tried to look for a solution for about one hour and couldn't find anything that works. Let me describe the problem.

I have a simple html form where the user uploads a file (.csv) and then also gives a delimiter for that file that I will be using to read it. The problem arises when the user submits a tab delimiter \t. When I try to access it in django

delimiter = request.POST['delimiter']

I get a string \\t which just corresponds to a string \t (not a tab). Is there a way to read the input as a tab or somehow convert anything with the escape character to the right form. The only way I figured out would be to do

delimiter.replace('\\t', '\t')

But then I would have to do this for \n etc. so there has to be a better way.

  • 1
    No, the *representation* of `\t` is `'\\t'. In reality it is a tab character. – Willem Van Onsem Jun 21 '21 at 17:42
  • I think this is happening inside the HTML form, immediately upon the user entering `\t`. – Ilya Jun 21 '21 at 17:44
  • Does this answer your question? [Process escape sequences in a string in Python](https://stackoverflow.com/questions/4020539/process-escape-sequences-in-a-string-in-python) (Essentially you just need to write `delimiter = delimiter.encode().decode("unicode_escape")`) – Abdul Aziz Barkat Jun 21 '21 at 17:49
  • @AbdulAzizBarkat that worked!!! thank you :) I read about `decode("unicode_escape")` but it didn't work without `encode()` – Gabriel Angel Jun 21 '21 at 18:00

0 Answers0