Skip to content

textwrap.wrap: new argument for more pleasing output #56694

Open

Description

@parent5446
mannequin
BPO 12485
Nosy @birkenfeld, @merwok, @bitdancer, @wiggin15
Files
  • textwrap.py-beautiful-2011-07-11_22-01-31_r71296+.diff: Addition of beautiful algorithm to textwrap.py
  • Issue12485.v2.patch: Addition of beautiful algorithm to textwrap.py with tests
  • 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:

    assignee = None
    closed_at = None
    created_at = <Date 2011-07-04.02:13:01.255>
    labels = ['type-feature', 'library']
    title = 'textwrap.wrap: new argument for more pleasing output'
    updated_at = <Date 2015-05-17.21:58:40.646>
    user = 'https://bugs.python.org/parent5446'

    bugs.python.org fields:

    activity = <Date 2015-05-17.21:58:40.646>
    actor = 'wiggin15'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2011-07-04.02:13:01.255>
    creator = 'parent5446'
    dependencies = []
    files = ['22626', '38978']
    hgrepos = []
    issue_num = 12485
    keywords = ['patch', 'needs review']
    message_count = 7.0
    messages = ['139731', '139785', '139825', '139827', '139880', '140170', '240827']
    nosy_count = 6.0
    nosy_names = ['georg.brandl', 'eric.araujo', 'r.david.murray', 'wiggin15', 'parent5446', 'gavanderlinden']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'test needed'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue12485'
    versions = ['Python 3.5']

    Activity

    1. parent5446 commented on Jul 4, 2011

      parent5446mannequin
      MannequinAuthor

      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.

    2. merwok commented on Jul 4, 2011

      @merwok
      Member

      Hi! Thanks for the report and patch. Are your two requests related? If not, it would be best to open two reports.

    3. added
      stdlibStandard Library Python modules in the Lib/ directory
      and removed on Jul 4, 2011
    4. changed the title [-]Improvement of textwrap module[/-] [+]textwrap.wrap: add control for custom length and orphans[/+] on Jul 4, 2011
    5. parent5446 commented on Jul 5, 2011

      parent5446mannequin
      MannequinAuthor

      Nah, they're both unrelated. I'll separate the changes and remake the patches. (I'll keep this entry for the beautification part.)

    6. parent5446 commented on Jul 5, 2011

      parent5446mannequin
      MannequinAuthor

      OK, so here is the patch for just the new algorithm.

    7. merwok commented on Jul 5, 2011

      @merwok
      Member

      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

    8. changed the title [-]textwrap.wrap: add control for custom length and orphans[/-] [+]textwrap.wrap: new argument for more pleasing output[/+] on Jul 5, 2011
    9. parent5446 commented on Jul 12, 2011

      parent5446mannequin
      MannequinAuthor

      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).

    10. gavanderlinden commented on Apr 14, 2015

      gavanderlindenmannequin
      Mannequin

      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.

    11. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions