Reputation: 31
with raw_input()
I need to enter '\t' to split one string. '\t' is regular expression. When provided through raw_input()
python transforms \t
to '\\t'
, so I cannot split the string.
line = '01/09/2015\t02:00\t0\t0\t0\t0\t0\t0\t1150592'
INPUT_separator = raw_input("- Separating character = ")
x = pd.DataFrame(line.split(INPUT_separator )).transpose()
Upvotes: 2
Views: 413
Reputation: 3011
\t
is not interpreted as a tab by raw_input()
hence decoding it would be necessary. But re
treats the literal \t
as a tab. Hence you can also use re
for this.
import re
line = '01/09/2015 02:00 0 0 0 0 0 0 1150592'
INPUT_separator = raw_input("- Separating character = ")
print re.split(INPUT_separator,line)
Upvotes: 1
Reputation: 23064
If you want to use the input \t
as a literal tab, you have to decode the escaped string input.
INPUT_separator = raw_input('Separating character = ').decode('string_escape')
Upvotes: 0