micropython-ulogger icon indicating copy to clipboard operation
micropython-ulogger copied to clipboard

can't import name TextIOWrapper

Open mttdr opened this issue 1 year ago • 2 comments

Hello, I'm trying to implement this library to handle logs in my project.

I copied the __init__.py and renamed it to ulogger.py, imported it in my main, tried to test following your examples but i get the error:

Traceback (most recent call last):
  File "main.py", line 6, in <module>
  File "ulogger.py", line 7, in <module>
ImportError: can't import name TextIOWrapper
MicroPython v1.20.0 on 2023-04-26; Raspberry Pi Pico with RP2040

By importing StringIO instead everything seems to be working correctly:

from io import StringIO

...

_file = StringIO

I simply tried this replacement by looking at what the REPL gave available on io module and picking what seemed to be the most probable guess.

Please let me know if i implemented ulogger in a wrong way or if my fix is not appropriate

mttdr avatar Jun 06 '23 11:06 mttdr

This is not a library designed for rp2040, it is recommended to use it on esp series development boards. There will be interpreter differences between different development boards. This is normal, but not sure if this method works on rp2040 it also means it will work on esp series.

However, in fact, there are differences between StringIO and TextIOWrapper, but if your modification is available on rp2040 and has no obvious impact on other platforms after testing, you are welcome to submit a pull request. But if your modification is only applicable to rp2040, it is recommended that you fork a new branch dedicated to rp2040, and then submit a pull request. If I can receive your pull request, I will sincerely thank you.

majoson-chen avatar Jun 06 '23 11:06 majoson-chen

Thank you for the quick response.

I'm a begginer learning as i go, so I don't feel confident recommending this fix to others. Doing a quick test it seems to work both on console and on file log, but I'll let more knowledgeable people decide.

I hope you understand my perspective :)

mttdr avatar Jun 06 '23 12:06 mttdr