Interaktive Python-Konsole ausführen

Die interaktive Python-Konsole, auch als Python-Interpreter oder Python-Shell bekannt, bietet Programmierern eine schnelle Möglichkeit, Befehle auszuführen und Code auszuprobieren und zu testen, ohne eine Datei zu erstellen. Die Introspektion von UNO-Objekten sowie die Dokumentation zu Collabora Office Python-Modulen können vom Terminal abgerufen werden.

note

Verwenden Sie in einem vollständig installierten Collabora Office entweder Basic oder Python:


Ein Basic-Makro verwenden

Sub interpreter_console
    Const UNIX = 4
    ps = CreateUnoService("com.sun.star.util.PathSettings")
    install_path = ConvertFromURL(ps.Module)
    cmd = IIF(GetGuiType()=UNIX,"x-terminal-emulator -e ","")
    Shell(cmd + install_path + GetPathSeparator() + "python" )
End Sub

Ein Python-Makro verwenden

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import uno, os, subprocess

def interpreter_console():
    ctx = XSCRIPTCONTEXT.getComponentContext()
    smgr = ctx.getServiceManager()
    ps = smgr.createInstanceWithContext("com.sun.star.util.PathSettings", ctx)
    install_path = uno.fileUrlToSystemPath(ps.Module)
    pgm = install_path + os.sep + "python"  # Python shell/console path
    subprocess.Popen(pgm)  # Start Python interactive Shell

Beispiel einer Ausgabe

Interaktive Python-Konsole

Alternative Konsole

Verwenden Sie die Konsole APSO-Erweiterung als eine Alternative:

APSO-Konsole

Bitte unterstützen Sie uns!