python - Split a user input -
i'd take user input delimiter , use split data. thought line of code should this:
my_delimiter = raw_input("write down delimiter of file(e.g. ','): ") line in file: line2 = line.split(my_delimiter) print line2 main_data.append(line2)
then sample input should
write down delimiter of file(e.g. ','): '\t'
and output should like
['age', 'prescript', 'astigmatic', 'tearrate\n'] ['young', 'myope', 'no', 'reduced', 'no lenses\n']
but remains same. doesn't work. not delimited tab or comma hope be. please me figure out.
if entering values '\t' in raw_input turns them str '\t' has 2 ascii characters. doesn't turn '\t' tab character want. if example, know going input '\t' , want turn tab character
my_delimiter = my_delimiter.replace('\\t', '\t')
this change actual tab character. have escaped characters '\r' , '\n' , on. should ask ascii values of characters separated ','. in case ask ascii value of '9' , turn int() , chr() , should work.
Comments
Post a Comment