Friday 15 July 2011

for loop - Need a program to exit after hitting a character python -


My script first reads the data file and then proceeds to analyze / plot it. I want the program to read the file line from the line and then stop looking for lines to kill # in the data file, on which I want to continue it on the rest of the code (plotting / analysis, etc.) I am I have been looking around and tried for sys.exit () and break , but they do not allow the program to continue the analytical process; Just gets out Completely lost.

For more information ....

  For Category I (WL): if (data [i] [0] == '#'): Comments = Comments + 1 other: # Analytical stuff # More stuff   

This was originally written. This is not my thing, so I think I get errors with this format, I want to improve it and want to make # one end character. After trying the suggestion of @Love_Livetsky, I now get the error of

  flux = np.append (flux, data [i] [1]) error: out of range index  < / Pre> 

Why does this happen?

I have a new look in the range (WL)

 : If in the '#' line: Break: #Neilles    

break is what you want it will take you out of that loop where you read the lines from the file, and Whatever you read after the loop:

  with open ('data') as f: for the line in f: if the line '#': break # # loop Do something else like add something to a list # data analysis O Do    

No comments:

Post a Comment