Basically I want to split the template string by literal whitespace (we don't have to worry about escape chars for these purposes) and produce an array of strings, where bracketed arguments with space on either side are by themself, otherwise they're joined to either side where there's a literal string with no whitespace in between. The code within the brackets should (if possible) be interpreted like it would be in an f-string, e.g. {1 + 1} -> "2". Here are some examples of my desired behavior:

my_var = "test"
args(t"foo bar ") # ["foo", "bar"]
args(t"{my_var} bar") # ["test", "bar"]
args(t"foo/{my_var}{my_var} bar") # ["foo/testtest", "bar"]
args(t"foo/{1 + 1} bar") # ["foo/2", "bar"]

0

Your Reply

By clicking “Post Your Reply”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.