HA! After much experimenting I hit upon getattr(__import__(page), page):
for page in self.allowedPages:
scriptPath = '{}/{}.py'.format(os.path.dirname(__file__), page)
if os.path.exists(scriptPath):
self.modules[page] = getattr(__import__(page), page)
Then in __call_ I just say:
tar
To explain my reasoning, this scheme will allow me to run the script three
ways, as shell, as one-shot CGI or as a persistent mod_wsgi module.
So to be more exhaustive:
In __init__ I can say:
import Grid
self.Grid = Grid.Grid
self.Grid is now the instance of Grid inside the module Grid.
then
On Fri, 02 Dec 2011 09:49:25 -0800, Gnarlodious wrote:
> What I am doing is importing modules that have an identical instance
> name. So I say:
>
> import Grid
>
> Grid has its instance:
>
> Grid.Grid()
>
> and this is the same for all modules of my webapp. allowedPages is a
> list of modules
Gnarlodious writes:
> What I am doing is importing modules that have an identical instance
> name.
Best to fix that, then.
> import Grid
That's a poorly-named module. PEP 8 recommends module names be all
lowercase.
> Grid has its instance:
>
> Grid.Grid()
And this is the reason: PEP 8 recomm
What I am doing is importing modules that have an identical instance
name. So I say:
import Grid
Grid has its instance:
Grid.Grid()
and this is the same for all modules of my webapp.
allowedPages is a list of modules to import, so they are quoted
strings:
for page in self.allowedPages:
seta