[Libreoffice] candidate for a new python section in SDK examples page

Miklos Vajna vmiklos at frugalware.org
Wed Dec 7 08:07:47 PST 2011


On Wed, Dec 07, 2011 at 03:49:10PM +0000, Michael Meeks <michael.meeks at suse.com> wrote:
> 	mod = __import__ ( "actual python-module-name" )
>         implHelper = mod.__dict__.get( "g_ImplementationHelper" , None )
> 
> 	is supposed to work, or indeed any half-way decent documentation on
> what the object is that __import__ returns and by what I don't mean
> floral vagueness but a concrete set of methods/properties and their
> types that would let us find an internal variable definition ;-)

----
mod = __import__("foo")
----

is the same as

----
import foo as mod
----

and in case foo and mod is the same, then it's the same as

----
import foo
----

So that form is just longer form in case the module to import is not
known at build-time, or in case for some weird reason the original
module name is not acceptable.

Second line:

----
implHelper = mod.__dict__.get( "g_ImplementationHelper" , None )
----

It "casts" the module to a dictionary (hasmap), then looks up the
"g_ImplementationHelper" key there: if it's not found, it falls back to
None.

In short, it checks if there is a funcion named "g_ImplementationHelper"
in "actual python-module-name".

(No, I'm not sure what else that dictionary contains, you can probably
fool that simple check by providing a *class* named
g_ImplementationHelper in the module, etc.)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/libreoffice/attachments/20111207/778ea009/attachment.pgp>


More information about the LibreOffice mailing list