[Tutor] Adding Value to CSV
alan.gauld at btinternet.com
Sun Nov 1 01:05:23 CET 2009
"Paras K." <paras80 at gmail.com> wrote
> When I have the line that has been read I need to add another value at
> end of it, or write the information into another csv file
If you are dealing with csv fioles you should look at using the csv module.
> for line in fh.readlines():
> readline = line
> ipline = readline
the readline and ipline variables are not needed. just use line!
> ip = ipline.split(' ')
> split_ip = ip.split('.')
> if ((split_ip == '"152')):
you don't need the parentheses here, its not C.
And you definitely don't need two sets of them!
> totalcount +=1
> I need to add another piece, how can I add another field at the end of
just add it to the end of line before writing it using any of the
normal string addition operations, eg:
line += newfield or
line = "%s%s" % (line,newfield)
Author of the Learn to Program web site
More information about the Tutor