Kae*_*vis 2 python pylint turtle-graphics visual-studio-code
我是编程新手,我下载了Python,并使其在Visual Studio Code中运行。我在弄乱turtle模块及其功能。
这些函数本身可以工作,但pylint会将其标记为错误,并说没有像我编写的代码那样的“成员”。
我将如何解决该错误?(我不想将其设置为“忽略”该问题,而是认识到我输入的代码是有效的并且来自于turtle模块)
turtle模块公开了两个接口,一个是功能接口,另一个是面向对象接口。功能接口是在加载时从面向对象的接口以编程方式派生的,因此静态分析工具看不到它,因此会pylint出现错误。代替功能接口:
import turtle
turtle.forward(100)
turtle.mainloop()
Run Code Online (Sandbox Code Playgroud)
对于pylint生成no-member,请尝试使用面向对象的界面:
from turtle import Screen, Turtle
screen = Screen()
turtle = Turtle()
turtle.forward(100)
screen.mainloop()
Run Code Online (Sandbox Code Playgroud)
这import对乌龟特别有用,可以阻止功能接口,我建议大家使用,因为人们经常通过混合OOP和功能接口而碰到错误。
| 归档时间: |
|
| 查看次数: |
1146 次 |
| 最近记录: |