Python Forum

Full Version: function on a different tab ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4
result:

3.4.0; MicroPython v1.20.0 on 2023-04-26
i installed:

micropython-pathlib

now i get:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: can't import name Path
I understand. I'm not used to MicroPython. We'll do without pathlib, use this code
import os
import sys
print('Cwd is {}'.format(os.getcwd()))
print('Current program is {}'.format(__file__))
print('Sys.path is {}'.format(sys.path))

import examplemod
I guess you don't have fstrings either.
it gives:

Cwd is /
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
NameError: name '__file__' isn't defined
(May-24-2023, 05:00 PM)trix Wrote: [ -> ]NameError: name '__file__' isn't defined
How did you run the code? Did you run it by typing F5 in the maintest.py window?
i'am pressing the green circle with te with triangel in it:

run current script (F5)
Again I find strange that __file__ is not defined but try to put this at the top of maintest.py
if '__file__' not  in vars():
    __file__ = sys.modules[__name__].__file__
result:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'vars' isn't defined

Angry
if '__file__' not  in globals():
    __file__ = sys.modules[__name__].__file__
I think MicroPython contains only a part of the standard library. There are good reasons for that I suppose.
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
NameError: name 'sys' isn't defined
Pages: 1 2 3 4