[英]Why isn't Python importing this correctly?
So, I have two files, HelloWorld.py and EnterExit.py. 因此,我有两个文件HelloWorld.py和EnterExit.py。 Here is the code for HelloWorld:
这是HelloWorld的代码:
import EnterExit
print('Hello world!')
print('What is your name?')
myName = input()
print('It is good to meet you, ' + myName + '!')
end()
And this is EnterExit: 这是EnterExit:
def end():
print('Press enter to continue')
input()
When I run HelloWorld, it works until end() is called. 当我运行HelloWorld时,它将一直工作到调用end()为止。 Then it says end() isn't defined.
然后,它说未定义end()。 What am I doing wrong here?
我在这里做错了什么?
Either write: 要么写:
EnterExit.end()
Or: 要么:
from EnterExit import end # or import *
end()
It is importing things correctly, you just need to refer to EnterExit.end()
. 它可以正确导入内容,您只需要引用
EnterExit.end()
。
Alternatively, import end
directly into your own globals: 另外,进口
end
直接到自己的全局变量:
form EnterExit import end
您需要调用EnterExit.end()
,或者
from EnterExit import end
You need to call it like EnterExit.end()
- there's nothing called end
in HelloWorld
itself. 你需要调用它像
EnterExit.end()
-没有什么所谓的end
在HelloWorld
本身。
If you want to call it as just end()
, you need to use 如果要仅将其作为
end()
调用,则需要使用
from EnterExit import end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.