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 LibreOffice pode ser obtida no terminal.

Usando uma macro Basic:


        Sub interpreter_console
            ps = CreateUnoService("com.sun.star.util.PathSettings")
            install_path = ConvertFromURL(ps.Module)
            Shell( install_path + GetPathSeparator() + "python" )
        End Sub
    

Usando uma macro 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
            
    

Utilização:

Console interativo Python

♥ Doe para nosso projeto! ♥