Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.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 web.py脚本一直在说:“我的';返回';“外部功能”;_Python_Error Handling_Web.py - Fatal编程技术网

Python web.py脚本一直在说:“我的';返回';“外部功能”;

Python web.py脚本一直在说:“我的';返回';“外部功能”;,python,error-handling,web.py,Python,Error Handling,Web.py,每当我尝试使用web.py运行此脚本时,都会收到错误消息 <type 'exceptions.SyntaxError'> at /hello 'return' outside function (app.py, line 19) 我试着重新缩进“返回”,但我只是得到了这个信息 您的代码混合了制表符和空格,这让Python感到困惑。您可以选择使用选项卡,也可以选择使用空格(建议使用空格),但必须保持一致 检查编辑器设置,看看是否可以告诉它以不同的方式显示选项卡和空格(大多数编辑器都可

每当我尝试使用web.py运行此脚本时,都会收到错误消息

<type 'exceptions.SyntaxError'> at /hello
'return' outside function (app.py, line 19)

我试着重新缩进“返回”,但我只是得到了这个信息

您的代码混合了制表符和空格,这让Python感到困惑。您可以选择使用选项卡,也可以选择使用空格(建议使用空格),但必须保持一致


检查编辑器设置,看看是否可以告诉它以不同的方式显示选项卡和空格(大多数编辑器都可以这样做)。

通过可视化空白或Python/Scripts/tabnanny.py检查选项卡/空格问题
import web
urls = (
'/hello', 'Index',
'/file_upload_form', 'ThatFile'
)

app = web.application(urls, globals())

render = web.template.render('templates/', base = "layout")

class ThatFile(object):
    def GET(self):
        return render.file_upload_form()

    def POST(self):
        form = web.input(image = "loc")
        image_o = open(form.image,'r')
        return render.thatfile(image_o = image_o)

class Index(object):

    def GET(self):
        return render.hello_form()

    def POST(self):
        form = web.input(name = "Nobody", greet = None)
        greeting = "%s, %s" % (form.greet, form.name)
        return render.index(greeting = greeting)

if __name__ == "__main__":
    app.run()