X Tutup
The Wayback Machine - https://web.archive.org/web/20210119193807/https://github.com/realpython/python-guide/issues/859
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Section idea: Elegant string formatting #859

Open
umbrae opened this issue Nov 16, 2017 · 1 comment
Open

Section idea: Elegant string formatting #859

umbrae opened this issue Nov 16, 2017 · 1 comment
Assignees

Comments

@umbrae
Copy link

@umbrae umbrae commented Nov 16, 2017

One thing that I would love to see is an opinionated guide to elegant string formatting in python. I feel like there are many ways to do it, especially with f-strings now, and when it comes to indentation, interpolation, longer method names, etc, and I can never decide in the moment on what the most elegant approach is. This is especially hairy when trying to conform to a 79 character line length.

This seems obviously up the python guide's alley. ;) Just wanted to drop the seed in case it had ever crossed y'alls mind.

Some examples I can think of:

  1. What should a long string parameter in a method call look like? (This often comes up in exceptions being raised for example.)

  2. What should a long string parameter with interpolation in an error message look like?

  3. What should a string look like in a case with deep-ish indentation? (other than: break out to a method). Same question with interpolation.

  4. f-strings or .format() or %? When/why?

  5. What should multi-line f-strings look like? Should they be avoided?

  6. When to triple quote? Docs only?

etc

I feel like there's an opportunity for really good guidance here that is outside of pep8; something everybody would run into that you all would have well-formed opinions on. :) And I haven't seen much written about it.

Thoughts?

@kennethreitz42
Copy link
Contributor

@kennethreitz42 kennethreitz42 commented Nov 16, 2017

This sounds like a great idea!

@mpoulin mpoulin self-assigned this Aug 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.
X Tutup