diff options
Diffstat (limited to 'helpcontent2/source/text/sbasic/python/python_shell.xhp')
-rw-r--r-- | helpcontent2/source/text/sbasic/python/python_shell.xhp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/helpcontent2/source/text/sbasic/python/python_shell.xhp b/helpcontent2/source/text/sbasic/python/python_shell.xhp new file mode 100644 index 000000000..0b724b88d --- /dev/null +++ b/helpcontent2/source/text/sbasic/python/python_shell.xhp @@ -0,0 +1,59 @@ +<?xml version="1.0" encoding="UTF-8"?> +<helpdocument version="1.0"> + <!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + --> + <meta> + <topic id="python_shell" indexer="include" status="PUBLISH"> + <title id="tit" xml-lang="en-US">Python Interactive Shell</title> + <filename>/text/sbasic/python/python_shell.xhp</filename> + </topic> + </meta> + <body> + <bookmark branch="index" id="N0117"> + <bookmark_value>Python console</bookmark_value> + <bookmark_value>Python Interactive Shell</bookmark_value> + </bookmark> + <section id="pythonshell"> + <paragraph role="heading" level="1" id="N0118"><variable id="pythonshell1"><link href="text/sbasic/python/python_shell.xhp" name="python shell">Running Python Interactive Console</link></variable></paragraph> + </section> + <paragraph role="paragraph" id="N0119">The Python interactive console, also known as Python interpreter or Python shell, provides programmers with a quick way to execute commands and try out and test code without creating a file. UNO objects introspection as well as %PRODUCTNAME Python modules documentation can be obtained from the terminal.</paragraph> + <paragraph role="heading" level="2" id="N0121">Using a Basic macro:</paragraph> + <bascode> + <paragraph role="bascode" id="N0122" localize="false">Sub interpreter_console</paragraph> + <paragraph role="bascode" id="N0123" localize="false"> ps = CreateUnoService("com.sun.star.util.PathSettings")</paragraph> + <paragraph role="bascode" id="N0124" localize="false"> install_path = ConvertFromURL(ps.Module)</paragraph> + <paragraph role="bascode" id="N0125" localize="false"> Shell( install_path + GetPathSeparator() + "python" )</paragraph> + <paragraph role="bascode" id="N0126" localize="false">End Sub</paragraph> + </bascode> + <paragraph role="heading" level="2" id="N0127">Using a Python macro:</paragraph> + <pycode> + <paragraph role="pycode" id="N0128" localize="false"># -*- coding: utf-8 -*-</paragraph> + <paragraph role="pycode" id="N0129" localize="false">from __future__ import unicode_literals</paragraph> + <paragraph role="pycode" id="N0130" localize="false"> </paragraph> + <paragraph role="pycode" id="N0131" localize="false">import uno, os, subprocess</paragraph> + <paragraph role="pycode" id="N0132" localize="false"> </paragraph> + <paragraph role="pycode" id="N0133" localize="false">def interpreter_console():</paragraph> + <paragraph role="pycode" id="N0134" localize="false"> ctx = XSCRIPTCONTEXT.getComponentContext()</paragraph> + <paragraph role="pycode" id="N0135" localize="false"> smgr = ctx.getServiceManager()</paragraph> + <paragraph role="pycode" id="N0136" localize="false"> ps = smgr.createInstanceWithContext("com.sun.star.util.PathSettings", ctx)</paragraph> + <paragraph role="pycode" id="N0137" localize="false"> install_path = uno.fileUrlToSystemPath(ps.Module)</paragraph> + <paragraph role="pycode" id="N0138" localize="false"> pgm = install_path + os.sep + "python" # Python shell/console path</paragraph> + <paragraph role="pycode" id="N0139" localize="false"> subprocess.Popen(pgm) # Start Python interactive Shell</paragraph> + <paragraph role="pycode" id="N0140" localize="false"> </paragraph> + </pycode> + <paragraph role="heading" level="2" id="N0141">Usage:</paragraph> + <paragraph role="paragraph" id="N0142"> + <image src="media/helpimg/python/python_shell.png" id="N0143"><alt id="N0144">Python Interactive Console</alt></image> + </paragraph> + <section id="relatedtopics"> + <embed href="text/sbasic/python/python_examples.xhp#pythonexamples2"/> + <embed href="text/sbasic/python/main0000.xhp#pythonscriptshelp"/> + </section> +</body> +</helpdocument> |