是的,但是在哪个文件中声明了pyth_test的定义?它在被调用之前是否也位于?
编辑:
要将其置于透视图中,请创建一个名为test.py的文件,其中包含以下内容:def pyth_test (x1, x2):
print x1 + x2
pyth_test(1,2)
现在运行以下命令:python test.py
你应该看到你想要的结果。现在,如果您正在交互会话中,则应如下所示:>>> def pyth_test (x1, x2):
... print x1 + x2
...
>>> pyth_test(1,2)
3
>>>
我希望这能解释宣言是如何运作的。
为了让您了解布局的工作原理,我们将创建一些文件。创建一个新的空文件夹,用以下命令保持干净:
myfunction.pydef pyth_test (x1, x2):
print x1 + x2
程序.py#!/usr/bin/python
# Our function is pulled in here
from myfunction import pyth_test
pyth_test(1,2)
现在如果你跑:python program.py
它将打印出3。现在为了解释出了什么问题,让我们这样修改我们的程序:# Python: Huh? where's pyth_test?
# You say it's down there, but I haven't gotten there yet!
pyth_te