我想在Python中定义一个函数,它本身使用numpy的函数,即sine函数sin。为了简化问题,我制作了一个测试函数“sine”_测试.py“如下:import numpy
def sine_test(theta):
return numpy.sin(theta)
我还想用一个名为u的sine函数运行_测试.py”并保存在同一目录中,其内容如下:
^{pr2}$
我希望它能把u定义为1弧度的正弦,大约0.84。两个“使用正弦_测试.py“和”正弦_测试.py“在同一个文件夹中(D:/Python)。但是,如果我运行“使用正弦_测试.pyPython脚本使用run按钮,我得到一个“NameError:global name'sin'isnotdefined”错误,如下所示。在
你知道是什么原因造成的吗?在
谨致问候,
库尔特%run D:/Python/use_sine_test.py
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
C:\Program Files\Enthought Python 7.2.2\lib\site-packages\IPython\utils\py3compat.py in execfile(fname, glob, loc)
166 else:
167 filename = fname
--> 168 exec compile(scripttext, filename, 'exec') in glob, loc
169 else:
170 def execfile(fname, *where):
D:\Python\use_sine_test.py in ()
1 import numpy
2 from sine_test import sine_test
----> 3 u=sine_test(1)
D:\Python\sine_test.py in sine_test(theta)
1 import numpy
----> 2 def sine_test(theta):
3 return numpy.sin(theta)
NameError: global name 'sin' is not defined