Jan-20-2020, 11:48 PM
i can't share the real code, but i can make an example. don't make other assumptions about this example. don't try to "solve" it some other way (the "solution" is probably not applicable to other cases)
if case1: ... foo,bar = ... ... print(f'foo = {foo!r} and bar = {bar!r}') ... if case2: ... foo,bar = ... ... print(f'foo = {foo!r} and bar = {bar!r}') ... if case3: ... foo,bar = ... ... print(f'foo = {foo!r} and bar = {bar!r}') ...what i want is something more like:
... pattern = 'foo = {foo!r} and bar = {bar!r}' ... if case1: ... foo,bar = ... ... print(fy(pattern)) ... if case2: ... foo,bar = ... ... print(fy(pattern)) ... if case3: ... foo,bar = ... ... print(fy(pattern)) ...where fy() in this example does the f-string-ify work. there will likely be a suggestion to have a function with the f-string coded once in the function and to call that function in each case, passing the variables to it. but that assumes a trivial set of variables. maybe there are too many. maybe they are unknown. maybe i'd like to read the pattern from a config file.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.