Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
817 views
in Technique[技术] by (71.8m points)

python - Where is my syntax error?

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']))

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')
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...