Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python函数中定义字符串?_Python_Google App Engine_Indentation_Syntax Error - Fatal编程技术网

如何在python函数中定义字符串?

如何在python函数中定义字符串?,python,google-app-engine,indentation,syntax-error,Python,Google App Engine,Indentation,Syntax Error,我第一次使用Python和googleappengine,但是无法在我的函数(mytest2)中定义一个字符串,在声明之后的行中出现了一个缩进错误。我可以在参数中定义一个有效的(测试),但不明白为什么我不能在函数中也这样做 我读了一些教程,但没有得到启发。有人能告诉我这里出了什么问题吗 我还想知道如何在类中定义类似mytest1的内容,然后在函数中进行访问 from google.appengine.ext import webapp from google.appengine.ext.weba

我第一次使用Python和googleappengine,但是无法在我的函数(mytest2)中定义一个字符串,在声明之后的行中出现了一个缩进错误。我可以在参数中定义一个有效的(测试),但不明白为什么我不能在函数中也这样做

我读了一些教程,但没有得到启发。有人能告诉我这里出了什么问题吗

我还想知道如何在类中定义类似mytest1的内容,然后在函数中进行访问

from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class MainPage(webapp.RequestHandler):
    #mytest1 = "test1" 
    #Runtime failure on this line talking about an indent issue
    def get(self, test = 'testing!'):
        mytest2= "test2" #Runtime failure on this line talking about an indent issue
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('Hello, webapp World!\n')
        self.response.out.write(self)
        #self.response.out.write('\n' + mytest1)
        self.response.out.write('\n' + mytest2)

application = webapp.WSGIApplication(
                                 [('/', MainPage)],
                                 debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main() 

一般公认的做法是使用4个空格进行缩进。这是在python样式指南中编写的。我强烈建议你读它

我通常将编辑器设置为用4个空格替换制表符,每个像样的文本编辑器都支持这一点


在您的示例中,制表符出现问题的原因是,它们最多被8个空格替换,缩进大部分是4个空格()

您是在混合制表符和空格吗?为什么是,是我!多简单啊。从来没有想过,也没有在任何介绍中提到过。太简单了!