Skip to content

Use f-strings instead of % formatting or str.format#167

Merged
kevinkjt2000 merged 2 commits intoDinnerbone:masterfrom
ItsDrike:fstrings
Nov 19, 2021
Merged

Use f-strings instead of % formatting or str.format#167
kevinkjt2000 merged 2 commits intoDinnerbone:masterfrom
ItsDrike:fstrings

Conversation

@ItsDrike
Copy link
Copy Markdown
Contributor

Since python 3.6, support for "f-strings" was added, this allows us to format strings in a very simple way:

variable = "some value"
foo = f"This string contains {variable}"

This is much more readable than using str.format or the % formatting notation.

I assume the reason these older ways to format strings was to keep the library compatible with older python versions, however at the moment, this library supports >=3.6 which allows us to utilize these f-strings instead of the less readable methods.


click.echo(f"version: v{response.version.name} (protocol {response.version.protocol})")
click.echo(f'description: "{response.description}"')
click.echo(f"players: {response.players.online}/{response.players.max} {player_sample}")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Much more readable than before, nice!

@kevinkjt2000 kevinkjt2000 merged commit d1c6c32 into Dinnerbone:master Nov 19, 2021
@ItsDrike ItsDrike deleted the fstrings branch November 21, 2021 03:52
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