<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Using the textwrap micropython module?]]></title><description><![CDATA[<p dir="auto">Has anyone tried this?</p>
<p dir="auto"><a href="https://github.com/micropython/micropython-lib/blob/master/textwrap/textwrap.py" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/micropython/micropython-lib/blob/master/textwrap/textwrap.py</a></p>
<p dir="auto">I managed to upload <a href="http://textwrap.py" target="_blank" rel="noopener noreferrer nofollow ugc">textwrap.py</a> to my device and it seems to import fine.  But whenever I attempt to use it I get an error. Here is the code I'm trying to work with:</p>
<pre><code>...
    req = urequests.request(method='GET', url='https://icanhazdadjoke.com/', headers={'Accept':'application/json'})
    dad_json = json.loads((req.text))
    DadJoke = dad_json['joke']
    wrapped = textwrap.fill(str(DadJoke),width=30)
    dad_joke.set_text_color(0x33ff33)
    dad_joke.set_text(wrapped)
</code></pre>
<p dir="auto">If I simply set_text(str(DadJoke)) it works but it writes right off the edge of the screen.</p>
]]></description><link>https://community.m5stack.com/topic/2681/using-the-textwrap-micropython-module</link><generator>RSS for Node</generator><lastBuildDate>Mon, 16 Mar 2026 20:56:41 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/2681.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 31 Dec 2020 22:52:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Using the textwrap micropython module? on Sun, 03 Jan 2021 16:23:39 GMT]]></title><description><![CDATA[<p dir="auto">I'd be open to any other methods you have for wrapping text.  Or even generic instructions for importing external micropython modules...</p>
<p dir="auto">This works fine in my local python interpreter:</p>
<pre><code>from textwrap import *
joke = "This is a really long joke. This is a really long joke.This is a really long joke.This is a really long joke.This is a really long joke."
wrapper = textwrap.TextWrapper(width=30)
print(wrapper.fill(joke))
</code></pre>
<p dir="auto">But when I try to run it on the m5stack device I get:</p>
<pre><code>'module' object has no attribute 'TextWrapper'
</code></pre>
]]></description><link>https://community.m5stack.com/post/11482</link><guid isPermaLink="true">https://community.m5stack.com/post/11482</guid><dc:creator><![CDATA[greenleaf]]></dc:creator><pubDate>Sun, 03 Jan 2021 16:23:39 GMT</pubDate></item></channel></rss>