Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't import name TextIOWrapper #6

Open
mttdr opened this issue Jun 6, 2023 · 4 comments
Open

can't import name TextIOWrapper #6

mttdr opened this issue Jun 6, 2023 · 4 comments

Comments

@mttdr
Copy link

mttdr commented Jun 6, 2023

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

@majoson-chen
Copy link
Owner

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.

@mttdr
Copy link
Author

mttdr commented Jun 6, 2023

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 :)

@bh1rio
Copy link

bh1rio commented Dec 19, 2024

哈喽,我在esp32的ports上也有这个问题

@majoson-chen
Copy link
Owner

哈喽,我在esp32的ports上也有这个问题

你好,检查您的 mpy 版本,可能版本过新,API 发生了变化,或者版本过久,不支持这个 API,这个库已经很久不更新,可以参考一楼自己做一下修改

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants