简体   繁体   中英

import & structure python modules / classes

im working on some basic python stuff within the google app engine and I was unable 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.

您需要将init.py重命名为__init__.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM