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
hello,

i,m programming a raspberry pi pico with the thonny IDE

its gonna be a big programm Smile
so i want to create some clear code.
to do that, i was wondering or it is possible to put a function on a different tab.
than i can switch comfortable between the tabs instead a lot of scrolling.

thanks in advance.
(May-12-2023, 04:28 PM)trix Wrote: [ -> ]to do that, i was wondering or it is possible to put a function on a different tab.
You can split the program into several files called Python modules and edit different files in different tabs.
Splitting up a file into smaller files just to avoid scrolling is a bad idea. Split a file into multiple smaller files if the new smaller files/modules each have a clear identity. If I had a program that maintained a database, did plotting, and generated reports I would give serious consideration into making a database module, a plotting module, and reports module. I would do this, not because the file is big when I put all that code in one file, but because these are somewhat independent activities.

If I was writing a user interface program that had several unique windows and dialogs I might put each window and dialog in their own file. Again, I would not do this to save space, but to organize the code so each module has a clear focus.

Does your program have logical divisions, or is it just long?
yes i think so, my machine where i writing a code for have different steps:

- read/write to the HMI (touchscreen)
- scanning a 2D object
- calculate/group 2D coördinates
- redrawing the object
- hand modus
hello,
i'am trying to create a module, but i'm facing a error.
i hope someone can tell me wat is wrong with the code.
thanks in advance Big Grin
[Image: modules.png?dl=1]
[Image: modules%282%29.png?dl=1]
What folder are you in? If you are not in the same folder as maintest.py and examplemod.py, the import will fail.

You could organize your files as a project, but I think you should just put all the files in the same folder for now.
tnx.
the are in the same folder
i added 2 printscreens shots.
but now on my work PC at work, i don' t see them any more Huh

edit:
maintest.py and examplemod.py are in the same folder: modules
is this not OK ?
(May-24-2023, 03:05 PM)trix Wrote: [ -> ]maintest.py and examplemod.py are in the same folder: modules
is this not OK ?
Normally it should work. It works for me with Thonny. Try to replace the code in maintest.py with the following, then paste the output here
from pathlib import Path
import sys
print(f'Cwd is {Path.cwd()}')
print(f'Current program is {__file__}')
print(f'Sys.path is {sys.path}')

import examplemod
it gives error:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: no module named 'pathlib'


can you see my added print screens ?
(May-24-2023, 04:06 PM)trix Wrote: [ -> ]ImportError: no module named 'pathlib'
In Thonny's Tools menu, select "manage packages". You can install pathlib there, but before that, this is strange because pathlib comes with Python since Python 3.4. Which version of Python are you using? Try this in the console
>>> import sys
>>> print(sys.version)
Pages: 1 2 3 4