[Tutor] Re: .....str.count and str.split/solved
Tim Johnson
tim at johnsons-web.com
Fri May 7 00:32:22 EDT 2004
Duh! Found it. Lines ended with a '\t'. Had used rsplit to
strip newline, also stripped all ending '\t', I'll bet....
<grin> Thanks for listening - wonder what perl->chomp would do...
tim
* Bob Gailer <bgailer at alum.rpi.edu> [040506 20:05]:
> At 09:58 PM 5/6/2004, Tim Johnson wrote:
> >Correction below:
> >* Tim Johnson <tim at johnsons-web.com> [040506 19:17]:
> >> Hello:
> >> I am importing TAB-delimited text data.
>
> Could you attach a sample file, and your code?
>
> >>
> >> 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
> >
> >_______________________________________________
> >Tutor maillist - Tutor at python.org
> >http://mail.python.org/mailman/listinfo/tutor
>
> Bob Gailer
> bgailer at alum.rpi.edu
> 303 442 2625 home
> 720 938 2625 cell
--
Tim Johnson <tim at johnsons-web.com>
http://www.alaska-internet-solutions.com
More information about the Tutor
mailing list