[Tutor] Breaking string at commas
Wesley J. Chun
wesc@deirdre.org
Mon, 12 Mar 2001 12:52:51 -0800
> From: "Shawhan, Douglas (GEAE, GECC)" <douglas.shawhan@ae.ge.com>
> Date: Mon, 12 Mar 2001 12:29:35 -0500
>
> I am trying to write a script that will take comma seperated text from a
> file, break the strings into seperate units at the linefeeds then seperate
> the comma seperated text into strings, insert html formatting then output
> the whole shebang into an html file.
douglas,
the basic recipe i would use is:
1. use file.readlines() to get list of input lines (broken @ linefeeds)
(the new file.xreadlines() can be used for large input files)
2. use string.split() to get comma-separated text string list
(split() [and join()] are string module functions or string methods)
3. use string.join() to merge the strings together with the HTML
formatting and calling file.write() to output to a HTML file
hope this helps!
-wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Silicon Valley-SF Bay Area Python users group: http://www.baypiggies.org
"Core Python Programming", Prentice Hall PTR, December 2000
http://www.phptr.com/ptrbooks/ptr_0130260363.html
wesley.j.chun :: wesc@baypiggies.org
cyberweb.consulting :: silicon.valley, ca
cyberweb_consulting@yahoo.com
http://www.roadkill.com/~wesc/cyberweb/