Bug 127351 - Example python script not execute
Summary: Example python script not execute
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Documentation (show other bugs)
Version:
(earliest affected)
6.3.1.1 rc
Hardware: All Linux (All)
: medium minor
Assignee: LibreOfficiant
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro-Documentation
  Show dependency treegraph
 
Reported: 2019-09-05 02:46 UTC by elmau
Modified: 2019-09-19 14:47 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description elmau 2019-09-05 02:46:27 UTC
Description:
The example: https://help.libreoffice.org/6.3/en-US/text/sbasic/python/python_shell.html?&DbPAR=BASIC&System=UNIX

Only work if LibreOffice is installed manuality, but not, if used the version of the distribution, because generally this versions used the Python Core the system, for this case:

import subprocess

def interpreter_console():
    subprocess.Popen('python')  
    return

Steps to Reproduce:
Only if used LibreOffice of the distribution

1. Copy and paste script
2. Execute

Actual Results:
Error: FileNOtFoundError

Expected Results:
Show interpreter console


Reproducible: Always


User Profile Reset: No



Additional Info:
Example: https://help.libreoffice.org/6.3/en-US/text/sbasic/python/python_shell.html?&DbPAR=BASIC&System=UNIX
Comment 1 LibreOfficiant 2019-09-06 14:46:16 UTC
Some distribution do not include LibreOffice Python Scripting Framework and propose it as an option e.g. ZorinOS

Some distribution propose LibreOffice Python Scripting Framework by default e.g.
Q4OS

I assume the help system is not meant to document the various installations and packages available in Linux distributions. 

However the presence of Python macros examples when selecting "Run macros.." is an indication that Python Scripting Framework is installed. It may be worth mentioning this in the wiki if not in the online help.

example Python macros are:
Capitalise
HelloWorld
LibreLogo
NamesRanges (New btw)
SetCellColor (New btw, no licence in this one)
pythonSamples
Comment 2 elmau 2019-09-06 15:04:43 UTC
Yes, I know, but 90% of users, use LibreOffice of distribution, so, 90% of cases, this code not will work. 

Only, add "tip" or note for this.

and add "return" to function.
Comment 3 elmau 2019-09-06 15:10:16 UTC
if not work, perhaps (generaly) the user assume it's LibreOffice
Comment 4 LibreOfficiant 2019-09-16 09:49:24 UTC
A 'note' enabling user check shall be added in the help.
Assigned to myself.

As for the 'return' hint, here's what PEP8 says:
«
Either all return statements in a function should return an expression, or none of them should. If any return statement returns an expression, any return statements where no value is returned should explicitly state this as return None , and an explicit return statement should be present at the end of the function (if reachable).
»

return statement shall be removed
Comment 5 elmau 2019-09-16 15:25:42 UTC
Thanks...


"Either all return statements in a function should return an expression, or none of them should"

I thing, for new users, it's better always used Return

By the way, PEP8 says for imports:


Yes: import os
     import sys

No:  import sys, os


Best regards
Comment 6 LibreOfficiant 2019-09-19 14:46:07 UTC
Python main page updated with Python framework check recommandation.

As for the import and return remarks, code is left AS IS for conciseness although not perfectly PEP 8 compliant. Please 'import this' for more.
Comment 7 LibreOfficiant 2019-09-19 14:47:01 UTC
https://gerrit.libreoffice.org/#/c/79177/