Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > cz.comp.lang.python > #3177

Re: [python] alternativa textwrap.fill(), která by zarovnávala po česku?

From Petr Přikryl <prikryl@atlas.cz>
Subject Re: [python] alternativa textwrap.fill(), která by zarovnávala po česku?
Newsgroups cz.comp.lang.python
Message-ID <mailman.3.1494487891.22440.python@py.cz> (permalink)
References <mailman.2.1494455290.22440.python@py.cz> <20170511093124.A5004794@atlas.cz>
Organization usenet-news.net
Date 2017-05-11 09:31 +0200

Show all headers | View raw


Modul textwrap je psaný v Pythonu a nemá to ani 300 řádků (i s rozsáhlými docstringy).
Přepište si to po svém, případně přidejte nějaký parametr typu "množina slov, která nemají zůstat na konci".
A pokud to bude šikovné, pošlete to jako námět na vylepšení oficiálního textwrap.

Přeji krásný den,
Petr


______________________________________________________________
> Od: Matěj Cepl <mcepl@cepl.eu>
> Komu: python@py.cz
> Datum: 11.05.2017 01:12
> Předmět: Re: [python] alternativa textwrap.fill(), kter
>
>On 2017-05-10, 22:28 GMT, Vláďa Macek wrote:
>> print textwrap.fill(instr, width=65).replace(u'~', 
>> unichr(160))
>
>No, udělal jsem v podstatě to:
>
>    diff --git a/reflow.py b/reflow.py
>    index 22b08cf..757077c 100644
>    --- a/reflow.py
>    +++ b/reflow.py
>    @@ -133,12 +133,18 @@ class ReflowPluginWindowActivatable(GObject.Object, Gedit.WindowActivatable):
>             if isinstance(text, str):
>                 text = unicode(text, 'utf8')
>     
>    +        # we don't want to break on the non-breaking space
>    +        # FIXME not sure whether there isn’t better replacement character
>    +        text = text.replace(unichr(0xA0), '~')
>    +
>             text = textwrap.fill(text,
>                                  width=self.get_gedit_margin(),
>                                  initial_indent=first_prefix,
>                                  subsequent_indent=prefix,
>                                  break_on_hyphens=False,
>                                  drop_whitespace=True)
>    +        text = text.replace('~', unichr(0xA0))
>    +
>             return text
>     
>         def _get_line(self, index):
>
>Ale nejsem na to hrdej. Navíc přemýšlím, jestli někdy nebudu 
>chtít mít ~ znak v textu. Ale snad ne.
>
>Hezký den,
>
>Matěj
>
>-- 
>https://matej.ceplovi.cz/blog/, Jabber: mcepl@ceplovi.cz
>GPG Finger: 3C76 A027 CA45 AD70 98B5  BC1D 7920 5802 880B C9D8
> 
>Of course I'm respectable. I'm old. Politicians, ugly buildings,
>and whores all get respectable if they last long enough.
>      --John Huston in "Chinatown."
>_______________________________________________
>Python mailing list
>python@py.cz
>http://www.py.cz/mailman/listinfo/python
>
>Visit: http://www.py.cz
>
>

Back to cz.comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

alternativa textwrap.fill(), která by zarovnávala po česku? Matěj Cepl <mcepl@cepl.eu> - 2017-05-10 21:35 +0200
  Re: [python] alternativa textwrap.fill(), která by zarovnávala po česku? Honza Král <honza.kral@gmail.com> - 2017-05-10 23:02 +0200
    Re: [python] alternativa textwrap.fill(), která by zarovnávala po česku? Matěj Cepl <mcepl@cepl.eu> - 2017-05-10 23:51 +0200
      Re: [python] alternativa textwrap.fill(), která by zarovnávala po česku? Vláďa Macek <macek@sandbox.cz> - 2017-05-11 00:28 +0200
        Re: [python] alternativa textwrap.fill(), která by zarovnávala po česku? Matěj Cepl <mcepl@cepl.eu> - 2017-05-11 01:12 +0200
        Re: [python] alternativa textwrap.fill(), která by zarovnávala po česku? Petr Přikryl <prikryl@atlas.cz> - 2017-05-11 09:31 +0200
          Re: [python] alternativa textwrap.fill(), která by zarovnávala po česku? Matěj Cepl <mcepl@cepl.eu> - 2017-05-11 10:50 +0200
            Re: [python] alternativa textwrap.fill(), která by zarovnávala po česku? Petr Viktorin <encukou@gmail.com> - 2017-05-11 11:22 +0200
              Re: [python] alternativa textwrap.fill(), která by zarovnávala po česku? Matěj Cepl <mcepl@cepl.eu> - 2017-05-11 16:31 +0200

csiph-web