python - 类和 Google App Engine

标签 python google-app-engine

我正在 Google App Engine 中试验简单的 Hello World 应用程序。我想创建一个单独的类,将其导入到 main.py 中并使用。

main.py:

import helloWorld

helloWorld.hi()

helloWorld.py:

class helloWorld():
    def hi():
        print 'Content-Type: text/plain'
        print ''
        print 'Hello, world!'

有什么解决方案可以让它发挥作用?

最佳答案

尝试这样的事情:

from helloWorld import helloWorld
helloWorld().hi()

或:

import helloWorld
helloWorld.helloWorld().hi()

第一个仅从模块helloWorld导入类helloWorld,您可以直接通过其名称使用它。

在第二个中,我们从模块 helloWorld 导入了所有内容,但我们只能使用 helloWorld.attr 语法来访问它。

Docs on modules .

并且 helloWorld 类的方法 hi 必须包含一个参数 self

def hi(self):

关于python - 类和 Google App Engine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16246014/

相关文章:

javascript - 连接两个动态创建的选择元素

python - 如何在 Google App Engine 中注册超过 10 个应用程序

google-app-engine - GoogleAppEngine urlfetch 超时异常

python - Matplotlib 中的 bin 大小(直方图)

python - 使用 Google App Engine 设置 Cherrypy

java - 在 App Engine Standard (Java 8) 中使用 Spring Boot Web 应用程序时出现空白页面

python - 什么会导致 Gdata Python 客户端在 appengine 中调用 YouTubeVideoQuery 时失败?

python - 通过第三个表排除多对多关系

python - 如何更改 qml 或 PySide2 中 XYSeries 中的所有点?

python - 基于模式分离列表的最优雅方式(Python)