@monorail s2e15, apparently
@vaporeon_ the names are conventional but the only impurrtant part is the * and **. a * arg is basically variadic arguments:
def fun(a, *args):
...
takes one required argument and any number of optional arguments, available in fun as a list bound to args
understanding the ** argument requires furst understanding the notion of "keyword" arguments. it is allowed to invoke the above function as fun(a=1). if it took mulitple arguments, i could supply keyword arguments in arbitrary order:
def fun2(a, b):
return b
fun2(1, 2) # 2
fun2(b=1, a=2) # 1
normally, it is a TypeError to supply an unexpected keyword argument to a function, but if there is a ** argument to the function, it is bound to a dict available the ** argument`s name:
def fun(**kwargs)
return kwargs
fun(a=2, b=3) # {'a': 2, 'b': 3}
an extremely common pattern is to write a thin wrapper around another existing function that takes keyword arguments. python has convenient syntax for inserting keyword arguments into a function call from a dict:
import requests
BASE_URI = # ...
def get(path, **kwargs):
# the HTTP methods in the requests library take a large number of optional keyword arguments
return requests.get(f"{BASE_URI}{path}", **kwargs)
auth_headers = # ...
print(get("/api/records", headers=auth_headers).json())
it’s pronounced “ashling”. canonically a black housecat or any of the grass cat pokémon, but currently experiencing daily TFs. Commewnist. it/she and more. i automatically change my pfp on the furst post of the day. (i suppurrt PluralDawn (https://exa.y2k.diy/garden/pluraldawn/) fur when i want to spontaneously change form fur a post or two)
GlitchCat syscatmin and meowstodev; @ me about techincal problems with the instance, or fur feature requests. i got a job due to some extent to my work on this instance
i am the kind of furry who is a weirdo horny freak (affectionate) about it but i don’t talk about that much on this account
available via email with the same username and domain. DM/email for other purrotocols
workplace policy is to clarify that all of my opinions expressed here are my own, and not those of my employer