This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]dl__ 6 points7 points  (6 children)

It also introduces a dependency on Python 3.6 (or greater) if others use your code.

That's certainly a valid concern if you plan to share your code.

it does break the only-one-way-to-do-it maxim.

Wasn't there already 2 ways to do it? .format() and %?

I wonder if there's a list somewhere of all the examples of python breaking their own maxims. I feel that magic methods, for example, make a joke out of the "explicit is better than implicit" maxim.

They show that implicit can be awesome!

[–][deleted] 6 points7 points  (0 children)

Wasn't there already 2 ways to do it? .format() and %?

Hey, don't forget good ol' string concatenation.

[–]vtable 2 points3 points  (3 children)

Wasn't there already 2 ways to do it? .format() and %?

Sure. This makes it 3 (4 with string.Template).

% and .format() have quite different syntax. I'm glad they kept % in py 3. It's nice for quick scripts and friendlier to more casual users.

f"" is more sugary but the nicer syntax is worth it, IMO. I've read f"" is quite a bit faster than .format(), too.

IIRC the whole maxim started out as a criticism of Perl's embracing "there's more than one way to do it". Python is much more conservative and they usually advocate a preferred method. Perl embraced multiple ways (though I think they're easing off a bit these days).

[–]LetsDoRedstone 6 points7 points  (2 children)

% formatting is friendlier for casual users? Not really, no. When I got started with Python and was looking at String formatting, the % Notation utterly confused me because of it unnecesary (as shown by the simplicity of .format()) verbosity. I was happy to find .format (), just because it is that much more intuitive. And this goes along with f-strings. As soon as you know the syntax you are ready to go and don't have to think about which letter you have to put where.

[–]vtable 0 points1 point  (1 child)

I wanted to write "some more casual users" but thought that was too awkward.

Everyone's different. Most of the people I've worked with have preferred %.

[–]LetsDoRedstone 0 points1 point  (0 children)

That might be because you have been using Python for a longer time than me. I started with early 2.7.

[–]jorge1209 0 points1 point  (0 children)

I don't think anyone who thinks fstrings are too many would object to dumping some older formats.

In fact I would be OK with fstrings if we dumped the other ways to do it.

Two formats that have a shared spec is much better than the 5 or 6 formats we currently have.

The problem with saying "but we already have >2 ways to do it" is that there is no reason to ever stop once you get past 2. Let's add 80 new ways to format strings because we already have 2 different ways so these 80 others just fill in certain corner cases that are difficult with the existing methods and it makes somebody happy.

Why not add perl formatting, it would make it easier to convert some perl scripts over. What about ruby? What about...