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: new argument for more pleasing output #56694
Comments
Python's textwrap module can be helpful at times, but personally I think there are a couple of things that could be added. First, when it comes to text wrapping, usually you're not dealing with a monospace font where each letter is the same size. If you're working with the Python Imaging Library for example, there is a function that you pass the text to in order to determine how wide (or tall) a font is. Therefore, it would be useful to have a parameter where the user can pass a function that gives a custom width for a set of text. The default for this parameter, of course, would be len. Also, this module uses a rough and efficient algorithm for wrapping text, but the results are not always aesthetically pleasing (one word hanging off on a line). Sometimes the user may want something that is wrapped more beautifully, so to say, such as is found in TeX. So there should also be a beautiful option that goes back and redistributes the text so that it is more aesthetically pleasing. This isn't exactly that important (minor improvements to a module that is probably not used much), but I figured I'd get it out there as I run into the problem all the time when trying to wrap text to be put in images of a set size. |
Hi! Thanks for the report and patch. Are your two requests related? If not, it would be best to open two reports. |
Nah, they're both unrelated. I'll separate the changes and remake the patches. (I'll keep this entry for the beautification part.) |
OK, so here is the patch for just the new algorithm. |
xrange does not exist in Python 3, it’s called range. You should have seen yesterday that I changed the versions: as a new feature, this cannot go into stable releases, only into the next one. I’m adding Georg to nosy per http://docs.python.org/devguide/experts |
OK, sorry to get back so late, but here's the updated patch without xrange. I saw the version change but forgot that I used xrange in the function (old habits I guess). |
Updated the patch and added tests. Fixed a problem with the previous patch: result of map function was assumed to be list, however map in Python3 returns an interator. So I replaced it with a list comprehension. |
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: