模块对象没有属性“屏幕" [英] module object has no attribute 'Screen'

查看:27
本文介绍了模块对象没有属性“屏幕"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在本网站自学 Python.在 Chapter 3 上,当我在给定的示例中输入代码时,我得到了以下错误--

Python 3.2 (r32:88445, 2011 年 3 月 25 日,19:28:28)[GCC 4.5.2] 在 linux2 上输入帮助"、版权"、信用"或许可"以获取更多信息.>>>进口龟回溯(最近一次调用最后一次):文件<stdin>",第 1 行,位于 <module>文件turtle.py",第 2 行,在 <module> 中wn = 海龟.Screen()AttributeError: 'module' 对象没有属性 'Screen'>>>

这是我需要下载和安装的东西吗?我尝试查看 docs.python.org,但我的鼻子开始流血,阅读所有这些技术资料.请指点我正确的方向好吗?谢谢.

解决方案

Adam Bernier 的回答 可能是正确的.看起来您有一个名为 turtle.py 的文件,Python 在安装 Python 附带的文件之前选择了该文件.

要追踪这些问题:

% 蟒蛇Python 2.7.1(r271:86832,2011 年 1 月 29 日,13:30:16)[GCC 4.2.1 (Apple Inc. build 5664)] 在达尔文上输入帮助"、版权"、信用"或许可"以获取更多信息.>>>导入系统>>>系统路径[...] # 你的 ${PYTHONPATH}>>>进口龟>>>乌龟.__文件__'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/turtle.pyc' # 应该在你的 Python 安装下.>>>

如果你看到这样的东西:

<预><代码>>>>进口龟>>>乌龟.__文件__'海龟.py'

然后您需要移动当前的 turtle.py(以及任何相应的 turtle.pycturtle.pyo 文件)工作目录不碍事.

根据下面的评论,您可以通过调用 help() 找到有关模块的大量信息,包括其路径名和内容.例如:

<预><代码>>>>进口龟>>>帮助(乌龟)

I am teaching myself python from this site. On Chapter 3, when I typed the code in the given example, I got the following error--

Python 3.2 (r32:88445, Mar 25 2011, 19:28:28) 
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import turtle
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "turtle.py", line 2, in <module>
    wn = turtle.Screen()
AttributeError: 'module' object has no attribute 'Screen'
>>> 

Is this something that I need to download and install? I tried looking into docs.python.org, but my nose started to bleed reading all that tech stuff. Kindly point me in the right direction please? Thank you.

解决方案

Adam Bernier's answer is probably correct. It looks like you have a file called turtle.py that Python is picking up before the one that came with your Python installation.

To track down these problems:

% python
Python 2.7.1 (r271:86832, Jan 29 2011, 13:30:16) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
[...] # Your ${PYTHONPATH}
>>> import turtle
>>> turtle.__file__
'/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/turtle.pyc' # Should be under your Python installation.
>>> 

If you see something like this:

>>> import turtle
>>> turtle.__file__
'turtle.py'

Then you'll want to move turtle.py (and any corresponding turtle.pyc or turtle.pyo files) in your current working directory out of the way.

As per the comments below, you'll find a wealth of information about a module, including its pathname and contents by calling help() upon it. For example:

>>> import turtle
>>> help(turtle)

这篇关于模块对象没有属性“屏幕"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆