-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
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
textwrap.wrap: add control for fonts with different character widths #56708
Comments
Originally from http://bugs.python.org/issue12485 but separated. The textwrap modules uses len to determine the length of text, but in many (if not most) fonts, the width of a character differs depending on the letter, so it would be useful to have an option to pass a custom function that returns the width of a given string of text. |
About the patch: the function should not be passed to the constructor, it could be a regular method that can be overridden in subclasses. |
Amaury, do you think it’s more common to subclass TextWrapper than just instantiate it? I find the proposed API (an argument to __init__) very intuitive. |
Normally I would have just added it as a function to be overloaded, but because of the nature of the textwrap.wrap function (all kwargs are passed to the TextWrapper constructor) I thought it made a lot more sense to keep it as an argument to __init__. |
Both approaches can be combined. It could be a regular overridable method, and it could be overridded for an instance if corresponding argument is specified. See the default method and parameter of JSON encoder. I slightly hesitate about the name. Is "width_func" the best of names? |
A PR was opened for this. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: