My code worked fine when it was all in one file. Now, I'm splitting up classes into different modules. The modules have been given the same name as the classes. Perhaps this is a problem, because MainPage
is failing when it is loaded. Does it think that I'm trying to inherit from a module? Can module/class namespace collisions happen?
MainPage.py
import BaseHandler
from models import Item
from Utils import render
class MainPage(BaseHandler):
def body(self, CSIN=None): #@UnusedVariable
self.header('Store')
items = Item.all().order('name').fetch(10)
render('Views/table.html', self, {'items': items})
self.footer()
BaseHandler.py
from google.appengine.ext import webapp
from google.appengine.api import users
from Utils import *
# Controller
class BaseHandler(webapp.RequestHandler):
# ... continues ...
Failure Traceback:
Traceback (most recent call last):
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3180, in _HandleRequest
self._Dispatch(dispatcher, self.rfile, outfile, env_dict)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 3123, in _Dispatch
base_env_dict=env_dict)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 515, in Dispatch
base_env_dict=base_env_dict)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2382, in Dispatch
self._module_dict)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2292, in ExecuteCGI
reset_modules = exec_script(handler_path, cgi_path, hook)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 2188, in ExecuteOrImportScript
exec module_code in script_module.__dict__
File "C:\Users\odp\workspace\Store\src\Main.py", line 5, in <module>
import MainPage
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1267, in Decorate
return func(self, *args, **kwargs)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1917, in load_module
return self.FindAndLoadModule(submodule, fullname, search_path)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1267, in Decorate
return func(self, *args, **kwargs)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1819, in FindAndLoadModule
description)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1267, in Decorate
return func(self, *args, **kwargs)
File "C:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1770, in LoadModuleRestricted
description)
File "C:\Users\odp\workspace\Store\src\MainPage.py", line 10, in <module>
class MainPage(BaseHandler):
TypeError: Error when calling the metaclass bases
module.__init__() takes at most 2 arguments (3 given)
UPDATE I appear to have solved it. This import works much better:
from BaseHandler import BaseHandler
Is it bad style to have the module and class name be the same?