[Tutor] help with existing code

Peter Otten __peter__ at web.de
Thu Jan 7 05:59:57 EST 2016


Brianna McGee wrote:

> I am a new to programming and have started out with modifying existing
> code to suit my purposes in my Developmental Psychology lab. The script
> worked fine previous to my fiddling with it, but now that I am trying to
> modify the x and y locations based upon a text file with existing x and y
> locations it will run but won't create the jpegs. I've attached an example
> of the text file. HELP! Please let me know if you need to see the rest of
> the code.
> 
>  if setsize == 4:
> 
>                 locations = open('X_Y_locations_SS4.txt', 'r')
> 
>                 i = 0;
>                 for line in locations:
>                     i = i+1;
> 
>                     if i % 2 != 0:
> 
>                         pointArray = line.split(",", 8);
>                         x1 = int(pointArray[0]);
>                         y1 = int(pointArray[1]);
>                         x2 = int(pointArray[2]);
>                         y2 = int(pointArray[3]);
>                         x3 = int(pointArray[4]);
>                         y3 = int(pointArray[5]);
>                         x4 = int(pointArray[6]);
>                         y4 = int(pointArray[7]);
> 
>    Thank you in advance!

I'm sorry, the chunk of code you present is not sufficient to diagnose your 
problem. 

Is setsize actually 4?
Does the inner loop run?

You can find out by adding print(...) function calls to the code (print 
statements if you are using python 2). If that works as you wish:

What did the code you replaced with the above look like? 
How are x1,y1,...,y4 used?

Give us a bit more context.





More information about the Tutor mailing list