Why is there difference between cmd line and .py file?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed Jan 6 00:33:49 EST 2016
On Wednesday 06 January 2016 07:25, Robert wrote:
> Why is there difference between cmd line and .py file?
Almost certainly because you are not running exactly the same code each
time.
> I run below code, which is downloaded from link:
Your code fails on the first line with
NameError: name 'np' is not defined
so you are obviously running something different from what you post here.
Since we don't know what code you are actually running, we cannot tell you
why it behaves differently when run as a .py file and in the interactive
interpreter.
But I am 99% sure that it is because you are running slightly different
pieces of code.
My *guess* is that in the code that works correctly, you are running:
import numpy as np
from numpy import sum
at the beginning of the .py script, but in the interactive shell, you are
just running:
import numpy as np
But there may be other differences as well.
--
Steve
More information about the Python-list
mailing list