realpython / realpython/python-guide
Section idea: Elegant string formatting
@mpoulin đang làm issue này rồi.
Từ ngày 31/8/2018.
- Ngôn ngữ chính
- Batchfile
- Star
- 29.8k
- Fork
- 5.9k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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:
-
What should a long string parameter in a method call look like? (This often comes up in exceptions being raised for example.)
-
What should a long string parameter with interpolation in an error message look like?
-
What should a string look like in a case with deep-ish indentation? (other than: break out to a method). Same question with interpolation.
-
f-strings or
.format()or%? When/why? -
What should multi-line f-strings look like? Should they be avoided?
-
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?
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Đánh giá
Issue này chưa được đánh giá.