Just to add a bit to user570039's answer, local_import is documented here. It includes a reload
parameter. According to the documentation:
When you specifyreload=True
, it will re-import the module upon each request; otherwise your python process will only import the module once. The default isreload=False
.
In development, setting reload=True
can be convenient because changes to your module will work immediately without requiring a restart. However, re-importing upon each request will slow down performance, so reload=False
is recommended in production.
UPDATE: Things have changed. local_import
has been deprecated. If you have /applications/myapp/modules/mymodule.py, you can import it within myapp by doing:
import mymodule
web2py will check the application's "modules" folder before checking the rest of sys.path.
For more details, see here.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…