<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Pythn to TextWrap in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/pythn-to-textwrap/m-p/569959#M44695</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am using MapTips (Layer Properties &amp;gt; Display &amp;gt; Display Expression).&amp;nbsp; I would like to use the advanced expression window to write a script using Python TextWrap.&amp;nbsp; Field string needs to be wrapped +-40 characters with no word split.&amp;nbsp; Attribute field is named BODY.&amp;nbsp; Unfortunately, I find the python.org page (syntax/example) much harder to read than ESRI's.&amp;nbsp; Has anyone attempted this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def FindLabel ( [Body] ): &amp;nbsp; return [Body]&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 17 Sep 2013 17:39:08 GMT</pubDate>
    <dc:creator>ReneeRafferty</dc:creator>
    <dc:date>2013-09-17T17:39:08Z</dc:date>
    <item>
      <title>Pythn to TextWrap</title>
      <link>https://community.esri.com/t5/python-questions/pythn-to-textwrap/m-p/569959#M44695</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am using MapTips (Layer Properties &amp;gt; Display &amp;gt; Display Expression).&amp;nbsp; I would like to use the advanced expression window to write a script using Python TextWrap.&amp;nbsp; Field string needs to be wrapped +-40 characters with no word split.&amp;nbsp; Attribute field is named BODY.&amp;nbsp; Unfortunately, I find the python.org page (syntax/example) much harder to read than ESRI's.&amp;nbsp; Has anyone attempted this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def FindLabel ( [Body] ): &amp;nbsp; return [Body]&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Sep 2013 17:39:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pythn-to-textwrap/m-p/569959#M44695</guid>
      <dc:creator>ReneeRafferty</dc:creator>
      <dc:date>2013-09-17T17:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: Pythn to TextWrap</title>
      <link>https://community.esri.com/t5/python-questions/pythn-to-textwrap/m-p/569960#M44696</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;from textwrap import fill def FindLabel([BODY]): &amp;nbsp;&amp;nbsp;&amp;nbsp; x = fill([BODY],40) &amp;nbsp;&amp;nbsp;&amp;nbsp; return x&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It should preferentially break lines at whitespace and dashes without any kind of intervention according to the doc. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Might need to move the 'from/import' inside the function:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;def FindLabel([BODY]): &amp;nbsp;&amp;nbsp;&amp;nbsp; from textwrap import fill &amp;nbsp;&amp;nbsp;&amp;nbsp; x = fill([BODY],40) &amp;nbsp;&amp;nbsp;&amp;nbsp; return x&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Sep 2013 19:54:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pythn-to-textwrap/m-p/569960#M44696</guid>
      <dc:creator>MattSayler</dc:creator>
      <dc:date>2013-09-17T19:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: Pythn to TextWrap</title>
      <link>https://community.esri.com/t5/python-questions/pythn-to-textwrap/m-p/569961#M44697</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The first one worked great!&amp;nbsp; The only thing I would change:&amp;nbsp; The left justification butts up against the label box.&amp;nbsp; But it does wrap nicely.&amp;nbsp; Thanks, Matt!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Sep 2013 17:14:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pythn-to-textwrap/m-p/569961#M44697</guid>
      <dc:creator>ReneeRafferty</dc:creator>
      <dc:date>2013-09-19T17:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: Pythn to TextWrap</title>
      <link>https://community.esri.com/t5/python-questions/pythn-to-textwrap/m-p/569962#M44698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;The first one worked great!&amp;nbsp; The only thing I would change:&amp;nbsp; The left justification butts up against the label box.&amp;nbsp; But it does wrap nicely.&amp;nbsp; Thanks, Matt!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Are you using a text background with the label (Advanced Text tab in properties)? The Balloon and Line Callout types have margin settings.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Sep 2013 17:25:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pythn-to-textwrap/m-p/569962#M44698</guid>
      <dc:creator>MattSayler</dc:creator>
      <dc:date>2013-09-19T17:25:22Z</dc:date>
    </item>
    <item>
      <title>Re: Pythn to TextWrap</title>
      <link>https://community.esri.com/t5/python-questions/pythn-to-textwrap/m-p/569963#M44699</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Matt, I'm not using a Properties &amp;gt; Label.&amp;nbsp; This is a maptip that you hover your cursor over and it gives you the body of text.&amp;nbsp; I am using maptips are under Properties &amp;gt; Display.&amp;nbsp; Have attached an example of lack of margin.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Sep 2013 20:19:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pythn-to-textwrap/m-p/569963#M44699</guid>
      <dc:creator>ReneeRafferty</dc:creator>
      <dc:date>2013-09-24T20:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: Pythn to TextWrap</title>
      <link>https://community.esri.com/t5/python-questions/pythn-to-textwrap/m-p/569964#M44700</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hhmm, could add spaces to pad things. I'm still on 10.1, so couldn't test using python, but it looked like the tooltip would keep the extra space when using VBScript. Kind of a hacky way to do it, but I'm not seeing a way to adust padding for tool tips. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;To accomplish this, use 'wrap' instead of 'fill', which returns a list containing each line, instead of the whole block of text. That will let you add a space to each line before adding it to the final block of text.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;from textwrap import wrap
def FindLabel([BODY]):
&amp;nbsp;&amp;nbsp;&amp;nbsp; y = ""
&amp;nbsp;&amp;nbsp;&amp;nbsp; x = wrap([BODY],40)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for item in x:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y += " " + item + "\n"
&amp;nbsp;&amp;nbsp;&amp;nbsp; return y&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:32:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pythn-to-textwrap/m-p/569964#M44700</guid>
      <dc:creator>MattSayler</dc:creator>
      <dc:date>2021-12-12T00:32:36Z</dc:date>
    </item>
  </channel>
</rss>

