[英]How can I uncache imported module in python?
This is really freaking me out. 这真让我感到震惊。 My project looks like this
我的项目看起来像这样
.
|-- main.py
|-- classes
| |-- __init__.py
| |-- exceptions.py
In those exceptions.py
, I initally created one exception called SecurityError
: 在这些
exceptions.py
,我最初创建了一个称为SecurityError
异常:
class SecurityError(Exception):
pass
I included the file in main.py
using from classes.exceptions import *
and SecurityError
normally works when I just raise
it. 我使用
from classes.exceptions import *
的文件将其包含在main.py
中from classes.exceptions import *
当我raise
其raise
时, SecurityError
通常可以正常工作。
Afterwards, I also added FilesystemError
, but whenever using it, I get: 之后,我还添加了
FilesystemError
,但是无论何时使用它,我都会得到:
global name 'FilesystemError' is not defined
未定义全局名称“ FilesystemError”
I tried to delete *.pyc
files in classes
directory but it has no effect. 我试图删除
classes
目录中的*.pyc
文件,但没有效果。 Any changes to the exceptions.py
take no effect, including any ridiculous ones that make the file invalid: 对
exceptions.py
任何更改均无效,包括使文件无效的任何可笑的更改:
class FileFOO BAR BAZ systemError(Exception):
pass
class SecurityErr foo bar bazor(Exception):
pass
The program still behaves as if the file never changed since the first run. 自第一次运行以来,该程序的行为就像文件从未更改过一样。 I don't think this behaviour has anything to do with intuitive programming - if there's cache, it should be in that directory.
我认为这种行为与直观的编程没有任何关系-如果有缓存,它应该在该目录中。
I am running the python directly from command line: 我直接从命令行运行python:
C:\programing\python\MyProject>py -2 main.py
Confusing errors of the form global name 'XXX' is not defined
typically mean that you are shadowing a standard library module. global name 'XXX' is not defined
形式的令人困惑的错误通常意味着您正在隐藏标准库模块。 You must rename your exceptions
module. 您必须重命名
exceptions
模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.