Using the URL object in kivy, https://kivy.org/doc/stable/api-kivy.network.urlrequest.html, if I wanted to change the on_success function to take in another parameter, how would I pass the value to it?
def generate_images(sensor_id):
req = UrlRequest(URL, on_success=url_success)
And then in the on_success having something like this
def url_success(req, result, sensor_id):
One solution is to use functools.partial()
:
from functools import partial
# ...
def generate_images(sensor_id):
req = UrlRequest(URL, on_success=partial(url_success, sensor_id))
# ...
def url_success(sensor_id, req, result):
print(sensor_id, req, result)
Another solution is to use a lambda
functions:
def generate_images(sensor_id):
req = UrlRequest(URL, on_success= lambda req, result, sensor_id=sensor_id : url_success(req, result, sensor_id))