Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


On Wed, Dec 07, 2011 at 03:49:10PM +0000, Michael Meeks wrote:

Any python genius that can tell me how:

I'm not sure I qualify as "genius", but let me try.

      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

http://docs.python.org/reference/datamodel.html and Python's source
code (Objects/moduleobject.c):

It is an object of type/class "module". Type module has exactly one
member:

__dict__ (read-only): the module's namespace as a dictionary
  (http://docs.python.org/library/stdtypes.html#typesmapping)

  __dict__ is the dictionary of attributes of the object. That is, if
  there is no member BAR in object FOO, then FOO.BAR is
  FOO.__dict__["BAR"]

__dict__ is prepopulated by the module loading system with:

_name__ is the module’s name

__doc__ is the module’s documentation string, or None if unavailable

__file__ is the pathname of the file from which the module was loaded,
  if it was loaded from a file. The __file__ attribute is not present
  for C modules that are statically linked into the interpreter; for
  extension modules loaded dynamically from a shared library, it is the
  pathname of the shared library file.

But they are read/write and can be freely changed by Python code.

let us find an internal variable definition ;-)

The code you quoted looks right. I would then continue with:

 if inspect.isroutine(implHelper):

to test whether implHelper is a function (something that takes
arguments and returns a result) as I guess it is expected to be. The
inspect module having been loaded, obviously.

-- 
Lionel

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.