vestige on Nostr: What's more idiomatic Python in this case? We are generating a log file. Using ...
What's more idiomatic Python in this case?
We are generating a log file. Using f-strings, one common mssage template including variable names is well over the 89 characters that Black formatter likes and this project's flake8 linter is configured for.<li>We could split the f-string into two or three strings joined within parens. Seems awkward given it prints as a single line, but oh well.</li><li>We could assign single-character variable names to use in the format string and maybe get it under 89 characters?</li><li>We could use string interpolation (% operator) or .format and put the variables on a separate line. It looks clean to me but it's not as obvious what variable goes where in the output.</li><li>We could leave it as-is and annotate the code so flake8 ignores the long line, then go get a coffee.</li><li>... Profit?</li>
The variable names are short. I'm curious whether anyone here has any strong opinions on the issue. (There are certainly some opinions on Stack Overflow...)
#python #codereview
Published at
2024-09-23 13:49:44 UTCEvent JSON
{
"id": "64d70b97512ebf5e06198062a061d16aaf8bd42a506d10f4916d75700d48607b",
"pubkey": "18285e83361ddbe2b494ce5e7acb09f9879e9acdf0fa443283026f9405f86d47",
"created_at": 1727099384,
"kind": 1,
"tags": [
[
"t",
"codereview"
],
[
"proxy",
"https://tech.lgbt/@vestige/113187185279718842",
"web"
],
[
"t",
"python"
],
[
"proxy",
"https://tech.lgbt/users/vestige/statuses/113187185279718842",
"activitypub"
],
[
"L",
"pink.momostr"
],
[
"l",
"pink.momostr.activitypub:https://tech.lgbt/users/vestige/statuses/113187185279718842",
"pink.momostr"
],
[
"-"
]
],
"content": "What's more idiomatic Python in this case?\n\nWe are generating a log file. Using f-strings, one common mssage template including variable names is well over the 89 characters that Black formatter likes and this project's flake8 linter is configured for.\u003cli\u003eWe could split the f-string into two or three strings joined within parens. Seems awkward given it prints as a single line, but oh well.\u003c/li\u003e\u003cli\u003eWe could assign single-character variable names to use in the format string and maybe get it under 89 characters?\u003c/li\u003e\u003cli\u003eWe could use string interpolation (% operator) or .format and put the variables on a separate line. It looks clean to me but it's not as obvious what variable goes where in the output.\u003c/li\u003e\u003cli\u003eWe could leave it as-is and annotate the code so flake8 ignores the long line, then go get a coffee.\u003c/li\u003e\u003cli\u003e... Profit?\u003c/li\u003e\n\nThe variable names are short. I'm curious whether anyone here has any strong opinions on the issue. (There are certainly some opinions on Stack Overflow...)\n\n#python #codereview",
"sig": "39aa57d1962684bf575f4ecec7304516db93743321856b89aaa39ed93fd8c02546875dccdad7e3fab317d5ee73762e402f33d9036d5432495c30f4efb2f0fc02"
}