The following code is close to what I am using without getting too long. I get the error TypeError: is_valid() takes exactly 2 arguments (3 given). To my eyes I am only passing 2 arguments. So where is the third argument coming from?
models/MyModel.py
from google.appengine.ext import db
class MyModel(db.model):
a = db.StringProperty(required=True)
b = db.StringProperty(required=True)
c = db.StringProperty(required=True)
class Update:
def is_valid(x, y)
myquery = db.GqlQuery('SELECT * FROM Valid WHERE value = :1' x)
v = myquery.get()
if v.something == y:
yet_more_stuff
return(True)
else:
return(False)
controllers/WebHandler.py
import webapp2
from models.MyModel import Update
class WebHandler(webapp2.RequestHandler):
def get(self):
var_x = "string"
var_y = "string"
z = Update()
if z.is_valid(var_x, var_y): <----- line error occurs
do_some_stuff
else
do_some_other_stuff
It is probably something simple but after coding for 18 hours today my brain has turned into oatmeal.
Solution
You have two solutions:
selffor consistency), orstaticmethoddecorator on the method.Explanation and examples
This line:
means that when the method is called,
xis the class instance andyis the argument. If you wanted to accept two arguments (and the instance itself), your line should look like that:But because you are not making any actions on the instance itself, you can also use
staticmethoddecorator:This will get rid of the instance being passed in the arguments and you will only receive the remaining arguments.