我的语法错误在哪里? [英] Where is my syntax error?

查看:312
本文介绍了我的语法错误在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试看到Python语法错误将被隐藏。 Django和pylint都会在custom.py:41中声明语法错误。第41-42行阅读:

I'm trying to see where a Python syntax error would be hiding. Both Django and pylint claim a syntax error at custom.py:41. Lines 41-42 read:

            (reading_threshold =
              int(request.POST['reading_threshold']))

我没有看到任何可以注意到该语句中的错误或custom.py中的语法。

I do not see anything that I can notice as wrong in that statement or the syntax in custom.py.

我的错误在这里是什么?

What is my mistake here?

文件的一个稍微消毒的版本是:

A slightly sanitized version of the file reads:

from django.http import HttpResponse

def threshold_check(user, item, text = None):
    if user.issuperuser():
        if text == None:
            return True
        else:
            return text
    else:
        if (user.status >= item.threshold and user.reading_threshold <=
          item.threshold):
            if text == None:
                return True
            else:
                return text
        else:
            if text == None:
                return False
            else:
                return ''

def threshold_check_required(item):
    def outer_wrap(view_function):
        def inner_wrap(request, *arguments, **keywords):
            if request.user.issuperuser():
                return view_function(request, *arguments, **keywords)
            else:
                if (request.user.status >= item.threshold and
                  request.user.reading_threshold <= item.threshold):
                    return view_function(request, *arguments, **keywords)
                else:
                    return HttpResponse('')
        return inner_wrap
    return outer_wrap

def threshold_controls(request):
    user = request.user
    if user and user.status != None:
        if request.method == 'POST':
            try:
                (reading_threshold =
                  int(request.POST['reading_threshold']))
            except ValueError:
                reading_threshold = user.reading_threshold
            try:
                (writing_threshold =
                  int(request.POST['writing_threshold']))
            except ValueError:
                writing_threshold = user.writing_threshold
            writing_threshold = min(user.status, writing_threshold)
            reading_threshold = min(writing_threshold,
              reading_threshold)
            user.reading_threshold = reading_threshhold
            user.writing_threshold = writing_threshold
            user.save()
        return render_to_response('threshold_controls.html',
          {
          'user': user
          })
    else:
        return render_to_response('threshold_controls_blank.html')


推荐答案

你正在看错误。 Python不是C;作业是一个声明,而不是一个表达式,所以你不能括号。

You're looking right at the error. Python isn't C; assignment is a statement, rather than an expression, so you can't parenthesize it.

这篇关于我的语法错误在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆