keyword-argument

Passing a function as an argument using internal parameters

Passing a function as an argument using internal parameters Question: I am just wondering if there is a solution to pass a function (fn2) as an argument (of fn1), and this function would use the internal parameters of the initial function (fn1) For example: def fn2(a: str): print("fn2 string print", a) def fn1(fn()): b = …

Total answers: 1

python decorator to check for already called func with unique arguments

python decorator to check for already called func with unique arguments Question: I m writing python decorator to check if func was previously called with same arguments. Below is proof of concept code storage = list() def f(*args, **kwargs): s = ” for i in range(len(args)): s += str(args[i]) kv = ” for k, v …

Total answers: 1

How to pass **kwargs as params to FastAPI endpoint?

How to pass **kwargs as params to FastAPI endpoint? Question: I have a function generating a dict template. This function consists of several generators and requires one parameter (i.e., carrier) and has many optional parameters (keyword arguments – **kwargs). def main_builder(carrier, **params): output = SamplerBuilder(DEFAULT_JSON) output.generate_flight(carrier) output.generate_airline_info(carrier) output.generate_locations() output.generate_passengers() output.generate_contact_info() output.generate_payment_card_info() output.configs(**params) result = output.input_json …

Total answers: 1

Pass dictionaries in function as arguments

Pass dictionaries in function as arguments Question: Im trying to create a function that take unknown number of arguments (dictionaries) to merge them in one. Here is my sketch: weight = {"sara": 60, "nick": 79, "sem": 78, "ida": 56, "kasia": 58, "slava": 95} height = { "a" : 1, "b": 2, "c":3 } width = …

Total answers: 3

How does "kwargs" is passed to a variable implicitly?

How does "kwargs" is passed to a variable implicitly? Question: A simple code from pytorch tutorial, which is used to load the data ”’ tr_data = datasets.FashionMNIST(root="data", train=True, download=True, transform=ToTensor()) ”’ However, when debug into the code as shown above. It use the "new" method without passing the "kwds". It seems the param "transform=ToTensor()" is …

Total answers: 1

How to handle flexible inputs and returns only keys in uppercase?

How to handle flexible inputs and returns only keys in uppercase? Question: The ideal output or results should be like below: >>> uppercase_keys_from_kwargs(twn=’Taiwan’) [‘TWN’] >>> uppercase_keys_from_kwargs(twn=’Taiwan’, jpn=’Japan’) [‘TWN’, ‘JPN’] >>> uppercase_keys_from_kwargs(twn=’Taiwan’, jpn=’Japan’, ltu="Lithuania") [‘TWN’, ‘JPN’, ‘LTU’] >>> uppercase_keys_from_kwargs(twn=’Taiwan’, jpn=’Japan’, ltu="Lithuania", svn=’Slovenia’) [‘TWN’, ‘JPN’, ‘LTU’, ‘SVN’] My Code just able obtain the keys only: def uppercase_keys_from_kwargs(**kwargs) …

Total answers: 2

Selectively passing kwargs in boto3 calls

Selectively passing kwargs in boto3 calls Question: Is there a way to selectively pass kw arguments on a boto3 call based on the value of the variable? For example, in a function call client.update_server(ServerId=server_id, Protocols=protocols, SecurityPolicyName=policy) if protocols is empty/None, my call should be client.update_server(ServerId=server_id, SecurityPolicyName=policy) And if policy is empty/None my call should be …

Total answers: 2

AirFlowException – Python_Callable must be callable

AirFlowException – Python_Callable must be callable Question: I made a small change to an existing workflow, and it has broken airflow. Here is the code: dag_name = platform + “_” + report[‘table’] dag = DAG( dag_name, catchup=True, default_args=default_args, schedule_interval=report[‘schedule’] ) with dag: trigger_report = PythonOperator( task_id=dag.dag_id + ‘_trigger_report’, python_callable=trigger_report, provide_context=True, op_kwargs={ ‘report_name’: report[‘report’], ‘amazonmws_conn_id’: default_args[‘amazonmws_conn_id’] …

Total answers: 4

How do I implicitly define a parameter to an empty list?

How do I implicitly define a parameter to an empty list? Question: In the code below, I’ve been wondering how we could tell if a parameter, b, is given. The problem is that the third call of func does not retain [5] in a newly created list but rather some pointer in the start that …

Total answers: 2