Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
New Python 3.0 string formatting - really necessary?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="Steven D'Aprano, post: 3703799"] I can't see how this is any different between what we have now. Here's an example using keyword arguments: # untested "{modifier} {noun}".format(modifier="dead", noun="parrot") "{noun} {modifier}".format(modifier="mort", noun="perroquet") compared to: "%(modifier)s %(noun)s" % dict(modifier="dead", noun="parrot") "%(noun)s %(modifier)s" % dict(modifier="mort", noun="perroquet") Whether using % or format(), I don't see the need to change the code, only the strings. Using positional arguments is not really that different: "{0} {1}".format("dead", "parrot") "{0} {1}".format("perroquet", "mort") versus: "%s %s" % ("dead", "parrot") "%s %s" % ("perroquet", "mort") In this case, the template on the left remains the same, you just have to reorder the string arguments on the right. Clearly less satisfactory than the solution using keyword substitution, but whatever solution you pick, I don't see any advantage to format() over % formatting. Can you show an example? [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
New Python 3.0 string formatting - really necessary?
Top