开发者

import & structure python modules / classes

开发者 https://www.devze.com 2023-01-29 13:51 出处:网络
im working on some basic python stuff within the google app engine and I was 开发者_如何学Cunable to figure out the correct way to structure my handlers.

im working on some basic python stuff within the google app engine and I was 开发者_如何学Cunable to figure out the correct way to structure my handlers.

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

the AccountHandler is basically a class

class AccountHandler(webapp.RequestHandler):

when im using from project.handlers import AccountHandler python always give me a

TypeError: 'module' object is not callable

how do i have to name/import/structure my classes?

cheers, Martin


To quote from the docs:

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

The AccountHandler you are importing is the module /project/handlers/AccountHandler.py in this case. The file AccountHandler.py is not callable, and the interpreter tells you this. To call the class you defined in your file just use:

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


You need to rename init.py to __init__.py

0

精彩评论

暂无评论...
验证码 换一张
取 消