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

Alan Gauld alan.gauld at btinternet.com
Sun Aug 16 23:57:49 CEST 2015


On 16/08/15 22:42, Nym City wrote:
> import socket
> import csv

You don't need csv, you aren't using it.

> in_file = open('top500ips.csv', 'r')
> out_file = open('top500ips_out.csv', 'w')
>
> for line in in_file:
>     try:
>         name = socket.gethostbyaddr(line.strip())
>         out_file.write(line + '\t' + (str(name))

count the parens in the line above...

>     except socket.herror:
>         out_file.write(line + '\t' + errrMsg)
>
> in_file.close()
> out_file.close()
>

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list