I've been trying to submit a solution in Python to a problem in Spoj, but I keep getting an NZEC runtime error.
Is it possible to find out which line the error is occurring at?
No, not directly: SPOJ won't tell you - it won't even tell you which non-zero exit code you got :-(
The slow way around this is to submit your program many times, changing it each time to exit at a later line. For example, call sys.exit() after your first line. If you don't get a NZEC complaint, you know your first line wasn't the cause. Then move sys.exit() down a line and try again. Etc. It can be a real PITA.
Note: you can do a form of binary search this way to find the offending line much faster.
Related
About 95% of the time I input something into my console (function of something, defined object, etc.) I don't get an output, instead, I get 3 dots, with a colon, as if it wants me to input something.
Often times I can just spam the variable into the console, and eventually instead of '...:', I'll get 'Out [###]:(thing I called)', but this is absolutely ridiculous.
I've never had this problem in 2.7. I've always used Spyder as my IDE.
I've done my research on here, asked around, but cannot solve this.
Thanks in advance :)
Screenshot of my problem
Another shot
I figured out the solution a couple months ago, I figured I would post it here for those who may be experiencing the same issue. Simply press Shift+Enter instead of just Enter, when inputting into Console. Stupidly simple solution. Thank you all again.
The python interpreter is expecting additional lines of code. Either you typed the wrong command or you made a mistake in what you typed. This will happen, for example, if you type part of a command and hit return. The interpreter is expecting the rest of the command.
I'm using a while loop in some code. This is the third one in this given program, all of them are formatted the same, yet for some reason one specific line is giving me syntax error. I have tried copying and pasting it directly from another portion of my while loop, and nothing seems to be rectifying it. I'm absolutely baffled. Perhaps another set of eyes can see what I'm missing?
close the parenthesis on the previous line
I have a bug in my code, but finding the exact cause of it is difficult because of how theano works.
Following the tips in the exception details, I set theano.config.optimizer='None' and theano.config.exception_verbosity='high', but that doesn't tell me enough.
In my case, for example, there is a problem with the dot product between two tensors. The stacktrace leads me through a lot and to a particular function which seems to contain in it, somewhere, the problematic call to theano.tensor.dot, but I can't find where exactly that part of the code is, and since I'm trying to implement things through keras, it gets even more complicated and tangled up.
Is there any way to get more details on an apply node? I've tried using StepMode, as it seems to be attached to the nodes, but if there is a way of making that tool print the exact lines from which the code in the node is executed, I don't know what it is. I tried using that to print a stacktrace when the problem occurs, but it prints just about the same stacktrace as the exception.
If you want to find the spots in your code that use theano.tensor.dot you can monkeypatch it with wrapper code that uses traceback.print_stack:
import traceback
original_dot = theano.tensor.dot
def debug_wrapper(*args,**kw):
traceback.print_stack()
return original_dot(*args,**kw)
theano.tensor.dot = debug_wrapper
This way any time theano.tensor.dot is called (after it is patched) it will show you the stack like the one in a traceback message and still do it's job. Note that I am not very familiar with theano so this is a general python debugging solution, there might well be ways specific to theano that let you do similar.
You should try using theano test_values. That way the exception will be raised exactly on the line where the error occurs and not after the compilation of the graph.
You need to change the theano.config.compute_test_value flag to 'raise' so that you get an error if there is an input tensor without a test_value, to make sure that all of the test computation will be propagated to the point where your error occurs.
I have the following python code inside a large loop
arr_a[indx]*arr_b[arr_c[indx],]
and with one running, an exception occurred and it said index out of range, but there are two possibilities(indx is out of range for predictErr, or arr_c[indx]), how do I know which part goes wrong?
This problem also extend to some general case that when one write several operations in one line and when things goes wrong, it is hard to tell which part causes this, and note that the above mentioned expression is inside a large loop, which means one can not simply start a debug mode and find that out.
Add a print statement for each segment that might be to blame to see which one fails:
print arr_a[indx]
print arr_c[indx]
arr_a[indx]*arr_b[arr_c[indx],]
I am not here to ask any solution. Please keep in mind. I am tring to solve a problem April challange. My solution gives correct output when i run it using python over my computer but it gives runtime error when i submit the code. I dont want to give the whole code as its ongoing contest.
I am sure i have taken care of all the boundary conditions.
Here is what i am trying to do. Simply i am traversing the array and doing some operations as given in the problem.
problem link(if u want to see ranges of integers used)
http://www.codechef.com/APRIL14/problems/ADIGIT
n,t=map(int,raw_input().split())
a=raw_input()
a=[int(s) for s in a]
while(t):
//do something
t=t-1
Most of the time runtime error occurs when you try to access the invalid memory or declare a huge bunch of memory.