Description: If I create a python macro in the user scripts directory that imports codefrom another module, the first time it is run I get the expected result. However if I modify the referenced module's code the "old" code still runs; even if I delete the __pycache__ directory between running. I assume the code is being cached elsewhere? Steps to Reproduce: 1. create a python file ~/config/libreoffice/4/user/Scripts/python/testmacro.py import anothermodule def set_some_text(): doc = XSCRIPTCONTEXT.getDocument() oSheets = doc.getSheets() sSheet = doc.getCurrentController().getActiveSheet() activeCell = doc.getCurrentSelection() activeCell.setString(anothermodule.get_something()) 2. create a python file ~/config/libreoffice/4/user/Scripts/python/pythonpath/anothermodule.py def get_something(): return "A" 3. Open Calc and run the macro "set_some_text". The letter A should appear. 4. Modify the anothermodule.py file and change to: def get_something(): return "B" 5. Open Calc and run the macro "set_some_text". I would expect the letter "B" to appear but it will instead set the cell to "A" still. Actual Results: "A" is set in the ActiveCell after changing anothermodule.py Expected Results: "B" is set in the ActiveCell Reproducible: Always User Profile Reset: Yes Additional Info: Version: 7.2.4.1 Build ID: 20(Build:1) CPU threads: 16; OS: Linux 5.15; UI render: default; VCL: gtk3 Locale: en-GB (en_GB.UTF-8); UI: en-US Calc: threaded
Alain, could you say your opinion please?
Modified imported Python modules require to restart LibO by design. Imported modules remain in memory until the LibO client is closed. Reflecting updates in imported modules requires to tweak your script using methods such as import.reload() or modules such as import-update.
Let's close as NAB by Comment 2
Thanks Alain, Roman. Working as expected now using reload(anothermodule)