Python Forum
function on a different tab ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
function on a different tab ?
#21
You must import sys first.
Reply
#22
i have now:

import sys
import os

if '__file__' not  in globals():
    __file__ = sys.modules[__name__].__file__

print('Cwd is {}'.format(os.getcwd()))
print('Current program is {}'.format(__file__))
print('Sys.path is {}'.format(sys.path))
 
import examplemod
result:

Error:
Traceback (most recent call last): File "<stdin>", line 5, in <module> KeyError: __main__
Gribouillis likes this post
Reply
#23
You might find this interesting.

https://wiki.micropython.org/gollum/Importing-Modules
Gribouillis likes this post
Reply
#24
i'm reading it already, tnx.
Reply
#25
Then you could perhaps just add the correct path to the directory containing the modules in sys.path, perhaps
import sys
sys.path.append('/modules')
at the top of maintest.py (or should it be 0:/modules ?)

Also better uninstall that micropython-pathlib module that you installed. Not sure what it is.
Reply
#26
the article says:

>>> import sys
>>> sys.path
['0:/', '0:/lib']


and i get:

>>> import sys
>>> sys.path
['', '.frozen', '/lib']


then:

So lets create a file, mod1.py which contains the following:

def hello():
print('hello from mod1')

and copy it to your internal flash


copy to your internal flash.....how to do that ?
just: save as
Reply
#27
These are pico questions. Maybe you will have better luck on a pico forum?

https://forums.raspberrypi.com/viewforum.php?f=143

BTW, I am sorry for earlier bad advice. I forgot that you were using micropython on a pico. The easiest route might be to use one file. I have no idea how to install modules on your device. I played with micropython on the LEGO Spike controller, and installing modules on that is a pain. I would write everything in one file, and after rigorous testing, I might pull out some of the code and install it as a module.
Reply
#28
maybe i have to uninstall thonny, and then install again ?

edit:
yes,..maybe i have to ask my question on the pico forum.

thanks for so far.
Reply
#29
it is working now Dance

here you can find my topic.

https://forums.raspberrypi.com/viewtopic...2#p2109672
Reply
#30
(May-26-2023, 05:18 PM)trix Wrote: it is working now Dance
That's great! Shocked I don't even understand the answers... What did you do to make it work?
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020