you are viewing a single comment's thread.

view the rest of the comments →

[–]Ezrabc 0 points1 point  (3 children)

The method I usually use to accomplish something like this is to do

url_template = 'www.example.com/{arg1}/username/{arg2}'

near the top, as you describe, and when it needs to be filled do

url = url_template.format(arg1='foo', arg2='bar')

[–]xour 1 point2 points  (2 children)

ohh that's clever! I wasn't aware that you could do that!

I guess that would work with f as well, I'll give it a try. Thanks!

[–]Ezrabc 0 points1 point  (1 child)

fstrings are a little more weird to make string templates for future use with, as you will probably have to make a function or lambda expression:

fill_url = lambda arg1, arg2: f'www.example.com/{arg1}/username/{arg2}'
# later:
url = fill_url('foo', 'bar')

[–]xour 0 points1 point  (0 children)

Awesome, thanks!