简体   繁体   English

Visual Studio Code (Python) 中未使用的变量警告

[英]Unused Variable warning in Visual Studio Code (Python)

Why do I get unused variable warning in Visual Studio Code, when there quite clearly is a use - just 3 lines below the offending variable declaration?为什么我在 Visual Studio Code 中收到未使用的变量警告,当有明显的用途时 - 仅在有问题的变量声明下方 3 行? Here the warning is given for variable这里对变量给出警告

found_r_object_id_in_cara

the variable is referenced in an 'if' statement a few lines below the declaration.该变量在声明下方几行的“if”语句中被引用。

在此处输入图片说明

Add these lines at the top of the program (Global declaration)在程序顶部添加这些行(全局声明)

# pylint: disable=unused-variable
# pylint: enable=too-many-lines

This may help someone.这可能会帮助某人。

Are you using the variable in question after setting the value inside if loop, if not the warning is valid.在 if 循环中设置值后是否使用相关变量,如果不是,则警告有效。 Setting and unsetting without actual usage will generate warning.在没有实际使用的情况下设置和取消设置将产生警告。 There are couple of ways to disable the warning ( although this one seems like legitimate).有几种方法可以禁用警告(尽管这似乎是合法的)。

you can put this above the line thats generating the warning:您可以将其放在生成警告的行上方:

#pylint: disable=unused-argument

Prefix the variable name with _ underscore用 _ 下划线前缀变量名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM