tensorly icon indicating copy to clipboard operation
tensorly copied to clipboard

Use f-strings instead of `str.format`

Open MarieRoald opened this issue 3 years ago • 2 comments

Currently, TensorLy uses the format-method for string formatting. However, in Python 3.6, f-strings were introduced, so the only reason to use the format-method instead of f-strings is for support of Python 3.5, which reached end-of-life in 2020. We can therefore safely replace all calls to str.format with f-strings, which is more readable. See example below:

x = 1.
s1 = "{}".format(x)
s2 = f"{x}"

s3 = "{:.1f}".format(x)
s4 = f"{x:.1f}"

print(s1 == s2)
print(s3 == s4)
True
True

More information is available in this tutorial: https://realpython.com/python-f-strings/

MarieRoald avatar Jul 13 '22 16:07 MarieRoald

Hello! I volunteer to take care of this issue.

bakhtos avatar Aug 03 '22 15:08 bakhtos

Great, thanks @bakhtos and welcome to the project!

JeanKossaifi avatar Aug 03 '22 18:08 JeanKossaifi

This should be complete!

aarmey avatar Dec 28 '22 20:12 aarmey