Passing a string containing keyword arguments to a function, combining into list comprehension
Discussions on Python.org
Passing a string containing keyword arguments to a function, combining into list comprehension
Having encountered the difficulty of passing a string of keyword arguments into a function I have found the solution below by converting the string into a dict. However I am having some difficulty combining the for...in loop in the str2dict() function into a one line list comprehension, if that is even possible? import ast def myFunc(arg1=None, arg2=None, arg3=None, arg4=None): print(f"{arg1=}, {arg2=}, {arg3=}, {arg4=}") def str2dict(str_in): dict_out = {} for pair in str_in.spl...
0 comments
No comments yet.