[Tutor] Writing back to same CSV in the next column
alan.gauld at btinternet.com
Mon Aug 17 10:35:13 CEST 2015
On 17/08/15 02:51, Nym City via Tutor wrote:
> the output of the gethostbyaddr module includes three item
> (hostname, aliaslist, ipaddrlist). However, in my output
> I just what the hostname field. So I created a list but
> I am not able to pull out just the  item from this
> and instead I get the following error:
> TypeError: 'int' object is not subscriptable.
> for line in in_file:
> name = socket.gethostbyaddr(line.strip())
Look at that last line and break it down.
Where is the index operation?
It's right at the end so it applies to the output
of the write() operation. You need it against
the list, before you convert to string and before
you write to file.
> Also, could you please give some explanation of '\t'.
Its the tab character. it inserts a tab, just like hitting
the tab key on the keyboard.
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:
More information about the Tutor