I have a function that asks for a delimiter. This can be \t. However, this is seen as a real tab. So if I have this code
def example(dataToBeSplit, delimiter):
return dataToBeSplit.split(delimiter)
example('some\ttext','\t')
The input given to example is example('some\ttext',' ')
How can I prevent the \t to be turned into a real tab, without having to give \\t to the function?
*if I put four actual spaces it gets filtered out, so see -four spaces- as four real spaces
edit:
Ok so from zefciu’s answer I now do
def example(dataToBeSplit, delimiter):
return dataToBeSplit.split(repr(delimiter))
example('some\ttext','\t')
But still wondering if there isn’t a way to do this in the
def example(dataToBeSplit, delimiter):
part
If you want to see the string in the form it can be accepted by python, use repr():