delimiting text file??

Gerrit Holl gerrit.holl at pobox.com
Thu Oct 14 15:37:27 EDT 1999


Aahz Maruch:
> In article <3804F889.30739C22 at bruer.org>, Jim Bruer  <jim at bruer.org> wrote:
> >
> >I've made it through the first 3 chapters of, Learning Python and
> >various online tutorials. With some excitement I'm trying to write my
> >FIRST program which will read a text file and comma delimit it, so it
> >can be read into a database table. I can read and write the file (line
> >by line) ok, but:
> >
> >How do you insert a delimiter into a string at a given position?
> >
> >Tried "f.insert(i,x)" then realized this is for mutable sequences.This
> >is so stupid I'm embarrassed to ask.
> 
> delimitedString = string[:x] + "," + string[x:]
> 
> That's a rather lame way to do it; as you learn more about Python,
> you'll come across better ways.

Is it? I think I've learned more about Python than Jim has (already finished
Learning python, and I'm waiting for Programming TkInter with Python now),
but I don't know a better way than this?

regards,
Gerrit.
-- 
linuxgames.nl.linux.org	 All about games on Linux in Dutch (under construction).
www.nl.linux.org	       The Dutch resource for Dutch Linux documentation.
www.nl.linux.org/discoverb		    Learn foreign words and definitions.
www.nl.linux.org/~gerrit/asperger	 I'm an Asperger, go here for more info.
www.nl.linux.org/~gerrit			    About me and pictures of me.




More information about the Python-list mailing list