Python 3.3.3 time.sleep() error [duplicate]

前提是你 提交于 2019-12-13 11:29:58

问题


I'm getting the following error:

The error:"Traceback (most recent call last):
  File "C:\Users\Jamie\Desktop\Python\ATM.py", line 8, in <module>
    time.sleep(2)
NameError: name 'time' is not defined"

here is my code:

http://pastebin.com/q2v7sdbz

Any ideas towards what may be throwing this?

Best,

Jamie


回答1:


the sleep function comes from the python time module so you to import before you call any of it's methods just put

import time

before you use any time stuff. It's normal to just put all of your imports at the top of your code.

see here for more info on importing:

https://docs.python.org/3/reference/import.html




回答2:


You need to import the time module. Just write import time at the top of your file on its own line to import it.



来源:https://stackoverflow.com/questions/23616507/python-3-3-3-time-sleep-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!