Alex Rivera | Logout

Classname same as file/module name leads to inheritance issue

Asked 2010-03-06T18:10:48.023
12

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\appen
Edit
Report

1 Answer

18

First of all the filenames should be all lowercase. That's Python convention that helps to avoid confusion such as this, at least most of the time.

Next, your import from withing MainHandler.py is wrong. You are importing BaseHandler (the module) and referencing it as if it were a class. The class is actually BaseHandler.BaseHandler. You need to reference it as such.

Try that and it should work for you.

answered 2010-03-06T18:16:31.050

Your Answer