[Tutor] Why Doesn't the for loop Increment?

Alan Gauld alan.gauld at yahoo.co.uk
Fri Jan 15 08:42:56 EST 2021


On 15/01/2021 13:24, Stephen P. Molnar wrote:
>
> with open('ligands_3') as ligand_file:
>
> for ligand in ligand_file:
>
You want to add a line here:


ligand = ligand.rstrip()


That will remove the linefeed which was read from the file.

Cameron had that in his code(I forgot!)...


> Now I'm really tearing out what little hair I have left - were did the
'\n' originate??????

It was in the original ligands file - separating the lines from each other.


--
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