Did I find the right examples for you? yes no

All Samples(1527)  |  Call(1463)  |  Derive(0)  |  Import(64)
Return the module an object was defined in, or None if not found.

        def getmodule(object, _filename=None):
    """Return the module an object was defined in, or None if not found."""
    if ismodule(object):
        return object
    if hasattr(object, '__module__'):
        return sys.modules.get(object.__module__)
    # Try the filename to modulename cache
    if _filename is not None and _filename in modulesbyfile:
        return sys.modules.get(modulesbyfile[_filename])
    # Try the cache again with the absolute file name
    try:
        file = getabsfile(object, _filename)
    except TypeError:
        return None
    if file in modulesbyfile:
        return sys.modules.get(modulesbyfile[file])
    # Update the filename to module name cache and check yet again
    # Copy sys.modules in order to cope with changes while iterating
    for modname, module in sys.modules.items():
        if ismodule(module) and hasattr(module, '__file__'):
            f = module.__file__
            if f == _filesbymodname.get(modname, None):
                # Have already mapped this module, so skip it
                continue
            _filesbymodname[modname] = f
            f = getabsfile(module)
            # Always map to the name the module knows itself by
            modulesbyfile[f] = modulesbyfile[
                os.path.realpath(f)] = module.__name__
    if file in modulesbyfile:
        return sys.modules.get(modulesbyfile[file])
    # Check the main module
    main = sys.modules['__main__']
    if not hasattr(object, '__name__'):
        return None
    if hasattr(main, object.__name__):
        mainobject = getattr(main, object.__name__)
        if mainobject is object:
            return main
    # Check builtins
    builtin = sys.modules['__builtin__']
    if hasattr(builtin, object.__name__):
        builtinobject = getattr(builtin, object.__name__)
        if builtinobject is object:
            return builtin
        


src/h/u/hunch-sample-app-HEAD/django/test/_doctest.py   hunch-sample-app(Download)
            module = None
        elif module is None:
            module = inspect.getmodule(obj)
 
        # Read the module's source code.  This is used by
        elif inspect.isclass(object):
            return module.__name__ == object.__module__
        elif inspect.getmodule(object) is not None:
            return module is inspect.getmodule(object)
        elif hasattr(object, '__module__'):

src/c/i/circuits-3.0.0.dev/examples/web/wiki/macros/__init__.py   circuits(Download)
 
import os
from inspect import getmembers, getmodule, isfunction
 
from creoleparser import parse_args
        m = __import__(moduleName, globals(), locals(), __package__)
 
        p = lambda x: isfunction(x) and getmodule(x) is m
        for name, function in getmembers(m, p):
            name = name.replace("_", "-")

src/m/u/Muntjac-1.1.2/muntjac/demo/sampler/Feature.py   Muntjac(Download)
    def getSource(self):
        if self._pythonSource is None:
            try:
                ex = self.getExample()
                self._pythonSource = inspect.getsource(inspect.getmodule(ex))

src/b/e/behave.example-HEAD/bin/toxcmd.py   behave.example(Download)
def discover_commands():
    commands = []
    for name, func in inspect.getmembers(inspect.getmodule(toxcmd_main)):
        if name.startswith("__"):
            continue

src/m/u/muntjac-HEAD/muntjac/demo/sampler/Feature.py   muntjac(Download)
    def getSource(self):
        if self._pythonSource is None:
            try:
                ex = self.getExample()
                self._pythonSource = inspect.getsource(inspect.getmodule(ex))

src/d/j/django-admin-report-HEAD/example/lib/reportlab/graphics/shapes.py   django-admin-report(Download)
def _addObjImport(obj,I,n=None):
    '''add an import of obj's class to a dictionary of imports''' #'
    from inspect import getmodule
    c = obj.__class__
    m = getmodule(c).__name__

src/p/l/plexnet-HEAD/source/plexnet/util/secure25.py   plexnet(Download)
 
    file = inspect.getsourcefile(object) or inspect.getfile(object)
    module = inspect.getmodule(object, file)
    if module:
        lines = linecache.getlines(file, module.__dict__)

src/d/i/dill-HEAD/dill/source.py   dill(Download)
from tokenize import TokenError
from inspect import ismodule, isclass, ismethod, isfunction, istraceback
from inspect import isframe, iscode, getfile, getmodule, getsourcefile
from inspect import getblock, indentsize, isbuiltin
from .dill import PY3
    raised for objects where the source code is unavailable (e.g. builtins)."""
 
    module = getmodule(object)
    try: file = getfile(module)
    except TypeError: file = None 
        file = sourcefile if sourcefile else file
 
        module = getmodule(object, file)
        if module:
            lines = linecache.getlines(file, module.__dict__)
        if not force: # don't try to get types that findsource can't get
            raise
        if not getmodule(object): # get things like 'None' and '1'
            if not instance: return getimport(object, alias, builtin=builtin)
            # special handling (numpy arrays, ...)
        return False
    # special handling (numpy arrays, ...)
    if not getmodule(object) and getmodule(type(object)).__name__ in ['numpy']:
        return True
    _types = ('<class ',"<type 'instance'>")

src/p/l/plexnet-HEAD/source/plexnet/util/secure30.py   plexnet(Download)
    is raised if the source code cannot be retrieved."""
    file = inspect.getsourcefile(object) or inspect.getfile(object)
    module = inspect.getmodule(object, file)
    if module:
        lines = linecache.getlines(file, module.__dict__)

src/p/l/plexnet-HEAD/source/plexnet/util/secure26.py   plexnet(Download)
    is raised if the source code cannot be retrieved."""
    file = inspect.getsourcefile(object) or inspect.getfile(object)
    module = inspect.getmodule(object, file)
    if module:
        lines = linecache.getlines(file, module.__dict__)

  1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9  Next