Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5023

MicroPython • Re: Improving Error Feedback

$
0
0
I had already thought of that but used the magic method

Code:

__import___ (file-name)
. Docs for __import__ are pretty vague, should I use exec?
I have absolutely no idea - I didn't even know about '__import__' - I just copy-pasted what I had used in some code !

I suspect the '__import__' may be more optimal because it doesn't have the processing overhead 'exec' would likely have.

Doing a quick test ... 'exec' seems to take 11480us to 11530us ... '__import__' seems to take 9400us to 9450us ... so a clear winner there.

I'd have to read the documentation but it may be that '__import__' behaves differently, may have different consequences to be aware of, but it appears to work. Anyway; you taught me something new. Thanks !

Statistics: Posted by hippy — Wed Jan 22, 2025 12:56 am



Viewing all articles
Browse latest Browse all 5023

Trending Articles