[Tutor] Writing back to same CSV in the next column

Alan Gauld alan.gauld at btinternet.com
Wed Aug 12 03:16:30 CEST 2015

On 12/08/15 01:58, Nym City wrote:

 > Please find the two requested files attached.

Since this is a text mailing list it's better to insert the files into
the email. Many servers will strip out attachments so they
can't be seen.

I've pasted them below.


After:    localhost    remote host    No resolution availabe for    localhost    No resolution availabe for

So, basically you just want to append the name (or an error message)?

In pseudocode this would be

open in_file
open out_file

for line in in_file:
          name = gethostaddr(line.strip())
          out_file.write(line + '\t' + name)
      except herror:
          out_file.write(line + '\t' + errrMsg)
close in_file
close out_file

delete in_file   # or rename to .bak
rename out_file to in_file

Can you translate that to Python?

Alan G
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:

More information about the Tutor mailing list