[Tutor] more spliting strings

Daniel Yoo dyoo@hkn.EECS.Berkeley.EDU
Mon, 21 Aug 2000 14:00:42 -0700 (PDT)


> >From the help I received from Remco, Amoreira and Denis, my little
> program searches a text file and gets rid of the lines with 'Total' in
> it and only reads the lines with a '$' in it.
> 
> Now I have to split this file up, but the file doesn't have any comma
> or tab deliminators.  It is a fixed length delimated file.
> 
> I only want the first 6 characters and the last 13 characters.  Then I
> want to add a date to the file in the first position.


Let's see what was causing the error:

> good_data = a + "," + line[:6] + "," + line[-13:]

This actually looks almost right --- you need to make sure that when
you're doing string concatenation that all of things you're adding up are
strings.  Since 'a' is defined as:

  a = ['08/18/00']

this explains that "TypeError" --- 'a' is not a string, but a
list.  However, the first item in a, a[0], is a string.


  good_data = a[0] + "," + line[:6] + "," + line[-13:]

will work.  It looks awkward to have a list with one item, unless you
really wanted that.  If not, it's simplest just to say:

  a = '08/18/00'

Also, the date is not Y2K compliant, so you might want

  a = '08/18/2000'

instead.  *grin*


Good luck!