在单独文档中的函数循环时,用于操纵布尔值
我只是构建一个简单的程序,并且遇到一个没有根据Pylance“访问”的变量。
我知道这通常是为dead Code发生的。
这是我拥有的:
主程序文件。
player_turn = True
while true:
#some code
我在一个单独的文件中仅用于逻辑函数,我有类似的东西。
def some_func():
#if some condition
player_turn = False
但是,在我的功能文件中,Pylance告诉我“未访问player_turn”。
我将变量从主程序导入到我的功能文件中。
而且我从上述文件中的功能正常导入到我的主程序文件中。
有什么建议吗?准备在这里学习新的东西!
提前致谢
I am just building a simple program and I'm encountering a variable not being "accessed" according to Pylance.
I understand that this usually happens for deadcode.
Here is what I have:
Main program file.
player_turn = True
while true:
#some code
I in a separate file for just logic functions I have something like this.
def some_func():
#if some condition
player_turn = False
However, in my function file, pylance is telling me that 'player_turn is not accessed.'
I've imported the variable from my main program into my function file.
And my functions from said file are properly being imported into my main program file.
Any suggestions? Ready to learn something new here!
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在此代码中
不正确
正确的代码是
谢谢
In this code
Is not correct
Correct code is
Thanks
应该提到的第一件事是
虽然true
循环在没有break
语句的情况下永远不会终止。另一个问题是,在函数中无法编辑全局范围中定义的不变数据。例如:
如果我要删除打印语句,则塔斯语会说
a
永远不会访问。The first thing that should be mentioned is that a
while True
loop never terminates without abreak
statement.Another problem is that immutable data defined in the global scope cannot be edited inside a function. For example:
If I were to remove the print statement, pylance would say
a
was never accessed.