python刷新/重新加载 [英] python refresh/reload

查看:107
本文介绍了python刷新/重新加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常基本的问题 - 但我一直无法通过在线搜索找到答案.

This is a very basic question - but I haven't been able to find an answer by searching online.

我使用 python 来控制 ArcGIS,我有一个简单的 python 脚本,它调用了一些预先编写的代码.

I am using python to control ArcGIS, and I have a simple python script, that calls some pre-written code.

但是,当我对预先编写的代码进行更改时,它似乎不会导致任何更改.我导入了这个模块,并尝试刷新它,但没有任何反应.

However, when I make a change to the pre-written code, it does not appear to result in any change. I import this module, and have tried refreshing it, but nothing happens.

我什至将它调用的文件移动到另一个位置,脚本仍然可以正常工作.我昨天做的一件事是我将所有 python 文件所在的文件夹添加到 sys 路径(使用 sys.append('path') ),我想知道这是否有所不同.

I've even moved the file it calls to another location, and the script still works fine. One thing I did yesterday was I added the folder where all my python files are to the sys path (using sys.append('path') ), and I wonder if that made a difference.

提前致谢,对于草率的术语表示抱歉.

Thanks in advance, and sorry for the sloppy terminology.

推荐答案

刷新"是什么意思不清楚,但 Python 的正常行为是您需要重新启动软件才能在Python 模块并重读.

It's unclear what you mean with "refresh", but the normal behavior of Python is that you need to restart the software for it to take a new look on a Python module and reread it.

如果您的更改在重启后仍未得到处理,则这是由于以下两个错误之一造成的:

If your changes isn't taken care of even after restart, then this is due to one of two errors:

  1. pyc 文件上的时间戳不正确,并且是未来的某个时间.
  2. 您实际上编辑了错误的文件.

即使不使用 reload() 命令重新启动软件,您也可以使用 reload 重新读取文件.请注意,任何指向模块中任何内容的变量都需要在重新加载后重新导入.像这样:

You can with reload re-read a file even without restarting the software with the reload() command. Note that any variable pointing to anything in the module will need to get reimported after the reload. Something like this:

import themodule
from themodule import AClass

reload(themodule)
from themodule import AClass

这篇关于python刷新/重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆