Interaktiwnu konsolu Python wuwjasć

Interaktiwna konsola Python, teke ako interpreter Python abo shell Python znata, programěrowarjam malsnu móžnosć bitujo, pśikaze wuwjasć a kod wopytaś a testowaś bźez togo, aby se dataja napórała. Introspekcija objektow UNO ako teke dokumentacija modulow Python LibreOffice datej se z terminala wótwołaś.

note

Wužywajśo pak Basic pak Python z dopołneje instalacije LibreOffice:


Makro Basic wužywaś


        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
    

Makro Python wužywaś


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

Pśikład wudaśa

Interaktiwna konsola Python

Alternatiwna konsola

Wužywajśo konsolu rozšyrjenja APSO ako alternatiwu:

Konsola APSO