I have a dictionary named dict1
in the file templates.py
. This dictionary contains several f-Strings, which take variables that are saved in the main file app.py
I do not know how to format the F-String if it is in another file.
I could technically just put the dictionary on the beginning of app.py
, but the dictionary is very long and it would not be an elegant solution.
CodePudding user response:
You can have a template as your string and then format it later. Here is an example (this string s
might be inside your dictionary):
s = '{} abc {} def {}'
result = s.format(*['hello', 'world', '!'])
If you print the result you will get:
'hello abc world def !'
You can't easily do this with f-strings though.