PyCharm 引用旧的、已删除的变量 [英] PyCharm referencing older, removed variable
问题描述
我刚刚遇到了 PyCharm 的问题.虽然我确实找到了解决方法,但我很想知道是否有更好的解决方案来解决这个问题.
I just encountered an issue with PyCharm. While I did find a workaround, I'm interested to know if there's a better solution to this issue.
在开发过程中,我有一个名为 rIndex 的变量.直到今天才注意到它抛出了以下错误,多次发送(2-4):
During development, I had a variable named rIndex. I didn't notice until today that it was throwing out the following error, sent multiple times (2-4):
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.1.4\helpers\pydev\_pydevd_bundle\pydevd_comm.py", line 1081, in do_it
result = pydevd_vars.evaluate_expression(self.thread_id, self.frame_id, self.expression, self.doExec)
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.1.4\helpers\pydev\_pydevd_bundle\pydevd_vars.py", line 352, in evaluate_expression
Exec(expression, updated_globals, frame.f_locals)
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2016.1.4\helpers\pydev\_pydevd_bundle\pydevd_exec.py", line 3, in Exec
exec exp in global_vars, local_vars
File "<string>", line 1
rIndex = {NameError}name 'rIndex' is not defined
^
SyntaxError: invalid syntax
我不知道是什么导致了这种情况,所以我将我的变量重命名为 rindex(替换每个实例),并删除了它的模块级实例化;基本上从我的代码的每一行中删除引用.(我通过对术语rIndex"执行 ctrl+F 来验证这一点,区分大小写.)
I have no idea what would cause that, so I renamed my variable to rindex (replacing every instance), as well as removed a module-level instantiation of it; essentially removing the reference from every line of my code. (I verified this by doing a ctrl+F with the term "rIndex", case sensitive.)
当我去重新运行脚本时,我再次遇到同样的错误,多次调用它.
When I went to re-run the script, I got the same error again, with multiple calls to it.
解决此问题的正确解决方案是什么?
What would be the proper solution to fixing this issue?
我的解决方法是创建一个新项目,然后复制代码.虽然这有效,但我想知道一种更正确的处理方式(特别是如果未来的项目有多个文件和设置).
My workaround was creating a new project, and copying the code over. While this worked, I would like to know a more-correct way of dealing with it (especially if future projects have multiple files and settings).
推荐答案
我遇到了类似的问题,我意识到我的旧变量上有观察者.当我从监视列表中删除一个变量时,错误消失了.
I was facing similar issue, I realized I had watchers on my old variable. Errors were gone when I removed a variable from the watchlist.
这篇关于PyCharm 引用旧的、已删除的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!