I am parsing sets of csv-type data into Python tuples by splitting the strings across a delimiting character. Very simple stuff.
My issue is that any of the fields could potentially contain empty strings as valid data. This is fine, except if the very last field is a empty string, in which case the length of the resulting tuple is one less than it should be.
For instance, given the following string, with commas as delimiters :
"2016-08-03,jim,,5146,,ok,,2,"
I desire the following output:
["2016-08-03", "jim", "", "5146", "", "ok", "", "2", ""]
While trying to find a simple solution to this problem, I found this answer, which details how to retain trailing empty strings in Java's split implementation. However, I have been unable to find anything equivalent in Python. Are there any alternative standard library methods or other simple tricks that would produce this behavior, or will I need add some additional logic into the script to accomplish this?
(I realize that it would be very simple to write a new method that produces this output, but in the interest of less code is better from a maintenance standpoint, I thought I would first check to see if I am missing something even easier.)