Skip to content

Migrate string formatting operations to str.format#1118

Merged
N-Parsons merged 1 commit into
exercism:masterfrom
N-Parsons:string-formatting
Nov 23, 2017
Merged

Migrate string formatting operations to str.format#1118
N-Parsons merged 1 commit into
exercism:masterfrom
N-Parsons:string-formatting

Conversation

@N-Parsons
Copy link
Copy Markdown
Contributor

I noticed that some of the exercises were still using the old style string formatting (eg."%s" % value) rather than using the newer str.format method - this PR moves everything to the newer style.

return "Take %s down and pass it around, " % (
"one" if current_verse > 1 else "it"
return "Take {} down and pass it around, ".format(
"one" if current_verse > 1 else "it",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was surprised that the Python interpreter doesn't complain about the trailing comma here; was there a particular reason for adding it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a stylistic thing that helps to avoid bugs and make diffs cleaner if someone adds an entry in future. It probably won't ever make a difference here, so I'm happy to remove them if you want - I mostly put them in to satisfy a flake8 extension that I have installed for other projects. They shouldn't cause issues though, since it's perfectly allowable in Python.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now you've got me curious: what's the extension? I've never seen an implementation of flake8/pep8/pyflakes that complains about those commas not being there.

Regarding this PR, I've no issue with leaving them. Was just curious.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's flake8-commas (PyPI). There are quite a few different extensions if you check pip search flake8.

@N-Parsons N-Parsons merged commit a2ade37 into exercism:master Nov 23, 2017
@N-Parsons N-Parsons deleted the string-formatting branch November 23, 2017 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants