2010-12-09 74 views
2

即时通讯工作在谷歌应用程序引擎的一些基本的python的东西,我无法找出构建我的处理程序的正确方法。导入和结构python模块/类

  • /main.py
  • /project/handlers/__init__.py
  • /project/handlers/AccountHandler.py

的AccountHandler基本上是一个类

class AccountHandler(webapp.RequestHandler): 

当使用从project.handlers进口AccountHandler python总是给我一个

TypeError: 'module' object is not callable

我该如何命名/导入/构造我的类?

欢呼声, 马丁

回答

6

the docs引用:

A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended.

AccountHandler要导入是在这种情况下,模块/project/handlers/AccountHandler.py。文件AccountHandler.py不可调用,解释器告诉你这一点。要调用您在文件中定义的类,请使用:

from project.handlers.AccountHandler import AccountHandler 
# Alternately 
# from project.handler import AccountHandler 
# AccountHandler.AccountHandler() # will also work. 
0

您需要重命名init.py__init__.py

+1

他有`__init __。py`。 Markdown刚刚将下划线解释为格式。 – 2010-12-09 21:48:28

+0

谢谢,我没有注意到格式。 – Velociraptors 2010-12-09 22:03:06