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

Alan Gauld alan.gauld at yahoo.co.uk
Wed Jan 13 10:36:40 EST 2021


On 13/01/2021 13:39, Stephen P. Molnar wrote:

> At this point in the testing I ran the code line by line (printing out 
> everything that happened) and got an interesting result on the execution 
> of line 9 as well as the remaining lines of code.

I'm not sure what you mean by that?
It looks like you typed it into the iPython interpreter?
Is that correct? If so the first error will cause all
the subsequent ones since the preceding code is effectively
not there.

> for ligand in df:
>    File "<ipython-input-5-269745371905>", line 1
>      for ligand in df:
>                       ^
> SyntaxError: unexpected EOF while parsing

I have no idea why yoiu are getting this but it could be an
ipython issue. Try running it in the regular pythopn interpreter,
or better still just as a script with actual print() statements
in it. When debugging reduce the number of variables to the
minimum and that means using the basic interpreter with a file.


> for i in num:
>    File "<ipython-input-6-e91b9883e5b7>", line 1
>      for i in num:
>                   ^
> SyntaxError: unexpected EOF while parsing

Again I'm not sure why. Looks like the same problem as above.

>    File "<ipython-input-7-6ad0f8600c09>", line 1, in <module>
>      name_in = "{}.{}.log".format(ligand, i)
> 
> NameError: name 'ligand' is not defined

This is just because the for line above failed so ligand never
got created.

Try putting the print statements into the code to print:
- df - potentially big, but at least a sample of it(use slicing maybe?)
- ligand - should see each value as the loop iterates - ie. N values
- name_in - should be different for each iteration - 10xN in total
- name_s - one per ligand - N values
- data[0,1]  - one per iteration, check against file contents

Show us the output.

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