【问题标题】:Unable to run turtle class in python无法在python中运行乌龟类
【发布时间】:2017-08-18 03:22:26
【问题描述】:

我收到以下错误:

Traceback (most recent call last):
  File "C:/Users/yashg/AppData/Local/Programs/Python/Python36-32/turtle2.py", line 1, in <module>
    import turtle
  File "C:/Users/yashg/AppData/Local/Programs/Python/Python36-32\turtle.py", line 18, in <module>
    draw_square()
  File "C:/Users/yashg/AppData/Local/Programs/Python/Python36-32\turtle.py", line 3, in draw_square
    window=turtle.Screen()
AttributeError: module 'turtle' has no attribute 'Screen'

【问题讨论】:

    标签: python python-3.x class turtle-graphics


    【解决方案1】:

    您应该将脚本重命名为 turtle.py 以外的名称。否则会阻止导入标准库turtle;首先搜索并导入您的模块,而不是标准库。

    还要确保turtle.pyc 没有留在目录C:\Users\yashg\AppData\Local\Programs\Python\Python36-32 中。

    【讨论】:

    • 嗨,谢谢您的快速回复但是即使更改了名称,我也遇到了同样的错误。正如您在上面的代码中看到的,我使用的是turtle2.py
    • @yash_g5,您在同一目录中有turtle.py,(也请检查turtle.pyc)。 (根据问题中给定的回溯)
    • thnx.. 我让它运行了... :)
    猜你喜欢
    • 2018-01-25
    • 2023-03-28
    • 1970-01-01
    • 2019-06-23
    • 2021-01-15
    • 1970-01-01
    • 2012-09-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多