[Tutor] problem with str.count and str.split
Tim Johnson
tim at johnsons-web.com
Thu May 6 23:58:27 EDT 2004
Correction below:
* Tim Johnson <tim at johnsons-web.com> [040506 19:17]:
> Hello:
> I am importing TAB-delimited text data.
>
> Each line is read in as a string with the newline removed.
>
> Each line is parsed into a list with TAB as a delimiter.
> code:
> vals = line.split('\t')
>
> It is expected that this line should have 75 TAB characters
> imbedded, and that the resulting list (vals) should have 76 members,
>
> An exception is thrown when a line is 'split' into a list
> with only 44 members, and when the exception is thrown,
> I use line.count('\t') to retrieve the number of embedded
> TABS and line.count('\t') returns the number 43.
>
> Visual Inspection:
> If I look at this line in an editor that allows
> TABS to be visible, I can manually count 75 TAB characters.
>
> Alternative Methods:
> This service was prototyped in another
> programming language (rebol) and all lines are
> being split successfully, finding 75 TABS and returning
> a list with 75 members.
a list with *76* members...
>
> I'd welcome comments, suggestions on this matter. I'm not about
> to get goofy and claim I've found a bug in python, I'm guessing
> that I should be using a more pythonesque approach to parsing
> these lines.
>
> thanks
> tim
> --
> Tim Johnson <tim at johnsons-web.com>
> http://www.alaska-internet-solutions.com
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
--
Tim Johnson <tim at johnsons-web.com>
http://www.alaska-internet-solutions.com
More information about the Tutor
mailing list