模块 turtle 没有 write 成员
Module turtle has no write member
我在 VS Code 上使用 Python,虽然我仍在学习一般的编码,但对此我有点困惑。
我正在运行宁此代码:
import scipy.integrate
import turtle
ans, err = scipy.integrate.quad(lambda x: x**2,0.,4)
print(ans)
turtle.write(ans, font=("Comic Sans", 40, "normal"))
作为我 运行 调试器,turtle 被标记并且 lint 说 turtle 没有写入成员,嗯,正确的。
我 运行 没有调试的代码和正确的 window 弹出但它在半秒后关闭。所有这一切,即使我在最后一行用 turtle 标记了中断。
为了查看我的代码是否有问题,我 运行 它在 PY shell 中并且它运行完美,没有问题。
我猜这个问题是 VS Code 特有的,虽然我不确定我是如何导入 turtle 的(我应该只导入我正在使用的函数吗?)
As I run the debugger, turtle is marked and the lint says that turtle
has no write member
Turtle 公开了两个接口,一个功能接口和一个 object-oriented 接口。功能接口是在加载时 派生的 ,因此静态分析工具看不到它,因此出现 lint 错误。而不是 功能性 界面:
import scipy.integrate
import turtle
ans, err = scipy.integrate.quad(lambda x: x**2, 0.0, 4)
turtle.write(ans, font=("Comic Sans", 40, "normal"))
尝试使用object-oriented界面:
import scipy.integrate
from turtle import Turtle, Screen
ans, err = scipy.integrate.quad(lambda x: x**2, 0.0, 4)
yertle = Turtle()
yertle.write(ans, font=("Comic Sans", 40, "normal"))
the correct window pops up but it closes after half a second
海龟程序通常以调用 mainloop()
方法(屏幕)或函数结束。这会将事件处理交给 tkinter。一些编程环境不需要它,但我相信他们知道禁用它。添加对 .mainloop()
的调用作为代码中的最后一件事,看看是否能解决您的问题:
screen = Screen()
screen.mainloop()
我在 VS Code 上使用 Python,虽然我仍在学习一般的编码,但对此我有点困惑。
我正在运行宁此代码:
import scipy.integrate
import turtle
ans, err = scipy.integrate.quad(lambda x: x**2,0.,4)
print(ans)
turtle.write(ans, font=("Comic Sans", 40, "normal"))
作为我 运行 调试器,turtle 被标记并且 lint 说 turtle 没有写入成员,嗯,正确的。 我 运行 没有调试的代码和正确的 window 弹出但它在半秒后关闭。所有这一切,即使我在最后一行用 turtle 标记了中断。
为了查看我的代码是否有问题,我 运行 它在 PY shell 中并且它运行完美,没有问题。
我猜这个问题是 VS Code 特有的,虽然我不确定我是如何导入 turtle 的(我应该只导入我正在使用的函数吗?)
As I run the debugger, turtle is marked and the lint says that turtle has no write member
Turtle 公开了两个接口,一个功能接口和一个 object-oriented 接口。功能接口是在加载时 派生的 ,因此静态分析工具看不到它,因此出现 lint 错误。而不是 功能性 界面:
import scipy.integrate
import turtle
ans, err = scipy.integrate.quad(lambda x: x**2, 0.0, 4)
turtle.write(ans, font=("Comic Sans", 40, "normal"))
尝试使用object-oriented界面:
import scipy.integrate
from turtle import Turtle, Screen
ans, err = scipy.integrate.quad(lambda x: x**2, 0.0, 4)
yertle = Turtle()
yertle.write(ans, font=("Comic Sans", 40, "normal"))
the correct window pops up but it closes after half a second
海龟程序通常以调用 mainloop()
方法(屏幕)或函数结束。这会将事件处理交给 tkinter。一些编程环境不需要它,但我相信他们知道禁用它。添加对 .mainloop()
的调用作为代码中的最后一件事,看看是否能解决您的问题:
screen = Screen()
screen.mainloop()