Python - how to call function from another py file?
I can't figure out how to separate my python macros into different files/modules. What I am trying to do is:
Have a LibreOffice button call: foo() and be able to call a function from another file (in the same directory)
foo.py -> foo.py$foo (user, Python)
from bar import bar
def foo():
bar()
bar.py
def bar():
print("Why does this not work?")
I keep getting different variations of: Message: <class 'importerror'="">: No module named 'bar' Message: <class 'importerror'="">: attempted relative import with no known parent package (or '.bar' is unknown)
What I have tried: (They are in the same directory for all of these)
- have the files in ~/.config/libreoffice/4/user/Scripts/python/
- have the files in /opt/libreoffice6.1/share/Scripts/python/
- All different types of from * import
- add empty __init__.py
- make bar a class and import it as and object
Full error I am getting: File "/opt/libreoffice6.1/program/pythonscript.py", line 1021, in getScript mod = self.provCtx.getModuleByUrl( fileUri ) File "/opt/libreoffice6.1/program/pythonscript.py", line 458, in getModuleByUrl exec(code, entry.module.__dict__) File "~/.config/libreoffice/4/user/Scripts/python/foo.py", line 19, in <module> from . import bar File "/opt/libreoffice6.1/program/uno.py", line 425, in _uno_import raise uno_import_exc File "/opt/libreoffice6.1/program/uno.py", line 347, in _uno_import return _builtin_import(name, optargs, *kwargs)