'Change a string in a for loop [duplicate]
I need a way to change an element of a string inside a for loop, in particular I have this:
N = 15
time_steps = np.linspace(0.005, 0.5, N)[:,None]
for ii in time_steps:
filter_results_file_name = 'augmented_filter_all_forces_ii.mat'
In particular I want that the string 'augmented_filter_all_forces_ii.mat' changes name in each iteration of the index ii, then for ii=0 I want 'augmented_filter_all_forces_0.mat', for ii=1 I want 'augmented_filter_all_forces_1.mat', and so on so forth.
Solution 1:[1]
You could simply use an 'f-string' in python Something like:
for ii in time_steps:
filter_results_file_name = f'augmented_filter_all_forces_{ii}.mat'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | moritz |
