Where is my syntax error?

2024/11/23 22:11: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']))

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 HttpResponsedef threshold_check(user, item, text = None):if user.issuperuser():if text == None:return Trueelse:return textelse:if (user.status >= item.threshold and user.reading_threshold <=item.threshold):if text == None:return Trueelse:return textelse:if text == None:return Falseelse: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 andrequest.user.reading_threshold <= item.threshold):return view_function(request, *arguments, **keywords)else:return HttpResponse('')return inner_wrapreturn outer_wrapdef threshold_controls(request):user = request.userif user and user.status != None:if request.method == 'POST':try:(reading_threshold =int(request.POST['reading_threshold']))except ValueError:reading_threshold = user.reading_thresholdtry:(writing_threshold =int(request.POST['writing_threshold']))except ValueError:writing_threshold = user.writing_thresholdwriting_threshold = min(user.status, writing_threshold)reading_threshold = min(writing_threshold,reading_threshold)user.reading_threshold = reading_threshholduser.writing_threshold = writing_thresholduser.save()return render_to_response('threshold_controls.html',{'user': user})else:return render_to_response('threshold_controls_blank.html')
Answer

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.

https://en.xdnf.cn/q/120607.html

Related Q&A

programming challenge: how does this algorithm (tied to Number Theory) work?

In order to work on my python skills, I am sometimes doing various challenges on the internet (eg on hackerrank). Googling for something else, I found this problem, and the accompanying solution on the…

Running total for list of dict

Have a python list of dict as following:Dict1 = [{date: 1, name: xyz, qty: 100},{date: 1, name: xyz, qty: 200},{date: 1, name: xyz, qty: 300},{date: 1, name: xyz2, qty: 30},{date: 2, name: xyz, qty: 10…

How to convert CSV file to a specific JSON format with nested objects?

I want to populate my json message with data from a CSV file. I want each row to be a "new" json object. I am using Python and will connect the the code to an API once done. Some of the data …

How do I repeat the program? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

How to parse json data in Python? [duplicate]

This question already has answers here:How can I parse (read) and use JSON in Python?(5 answers)Closed 10 years ago.Please help me to parse this json in python.{ "IT" : [ { "firstName…

Why did they opt for the message most recent call last? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed last month.Improve …

AttributeError: NoneType object has no attribute current

class LoginScreen(Screen):def __init__(self,**kwargs):super(LoginScreen, self).__init__(**kwargs)print self,self.parent.currentclass AppScreenManager(ScreenManager):pass#Base Class class AppBaseClass(A…

Python urllib2 or requests post method [duplicate]

This question already has answers here:Submitting to a web form using python(3 answers)Closed 8 years ago.The community reviewed whether to reopen this question 9 months ago and left it closed:Original…

How to fix Django NoReverseMatch Error

I have built a simple blog app with Django and I have had some issue with NoReverseMatch. Here are my problem screenshots: https://prnt.sc/imqx70 https://prnt.sc/imqwptHere is my code on Github: https:…

Selenium NoSuchElementException with driver.find_element_by_xpath

First question: How do I make python minimize chrome? Second question: When getting to the end page using the next button how do I tell python to go on.. and not give me an error?driver.get("htt…