Using the textwrap micropython module?
-
Has anyone tried this?
https://github.com/micropython/micropython-lib/blob/master/textwrap/textwrap.py
I managed to upload textwrap.py 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:
... 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)If I simply set_text(str(DadJoke)) it works but it writes right off the edge of the screen.
-
I'd be open to any other methods you have for wrapping text. Or even generic instructions for importing external micropython modules...
This works fine in my local python interpreter:
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))But when I try to run it on the m5stack device I get:
'module' object has no attribute 'TextWrapper'
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login