Executar o interpretador interativo do Python

O console interativo Python, também conhecido como interpretador Python ou shell Python, fornece aos programadores uma maneira rápida de executar comandos e testar o código sem criar um arquivo. A introspecção de objetos UNO e a documentação dos módulos Python do Collabora Office pode ser obtida no terminal.

note

A partir de uma instalação completa do Collabora Office, use Basic ou Python:


Usando uma macro em Basic

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

Usando uma macro em Python

# -*- 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

Saída de exemplo

Console Interativo Python

Console alternativo

Use o console da Extensão APSO como uma alternativa:

Console APSO

♥ Doe para nosso projeto! ♥