python - Function call using import in web2py -
i have split code multiple files. have imported functions other files admin.py. lets want call function xyz. if give path function admin/xyz
gives me error invalid function , have give path file_with_xyz_function/xyz
.
is there way overcome problem , simple call imported functions 1 single file
note: might not answering question i'm not sure understand question...
but if want put code (shared) module , include several of controllers suggest have @ chapter 4 (the core) of web2py book , search local_import
.
for kind of situation, web2py provides way import modules in such way global sys.path not altered: placing them in "modules" folder of application. 1 side benefit module automatically copied , distributed application; however, there restrictions apply. web2py provides local_import function must used import modules "modules" folder.
the import of modules depends on modules , web2py can find them. if standard module web2py can find in sys.path or in web2py/site-packages import modulename
should work expected.
for modules local app web2py offers else: applications/appname/modules
those modules can imported using local_import
.
mymodule = local_import(themodule)
this imports module name themodule in apps local modules folder , makes available under name mymodule. note local_import supports 2 additional arguments: reload , app. during development module code changes don't forget tell web2py reload module upon each request parameter reload=true
, otherwise won't see changes unless restart web2py.
Comments
Post a Comment