All Samples(205) | Call(199) | Derive(0) | Import(6)
Work out which source or compiled file an object was defined in.
def getfile(object):
"""Work out which source or compiled file an object was defined in."""
if ismodule(object):
if hasattr(object, '__file__'):
return object.__file__
raise TypeError('{!r} is a built-in module'.format(object))
if isclass(object):
object = sys.modules.get(object.__module__)
if hasattr(object, '__file__'):
return object.__file__
raise TypeError('{!r} is a built-in class'.format(object))
if ismethod(object):
object = object.im_func
if isfunction(object):
object = object.func_code
if istraceback(object):
object = object.tb_frame
if isframe(object):
object = object.f_code
if iscode(object):
return object.co_filename
raise TypeError('{!r} is not a module, class, method, '
'function, traceback, frame, or code object'.format(object))
import types
# For purposes of monkeypatching inspect to fix a bug in it.
from inspect import getsourcefile, getfile, getmodule,\
ismodule, isclass, ismethod, isfunction, istraceback, isframe, iscode
# IPython's own modules
FIXED version with which we monkeypatch the stdlib to work around a bug."""
file = getsourcefile(object) or getfile(object)
# If the object is a frame, then trying to get the globals dict from its
# module won't work. Instead, the frame object itself has the globals
# dictionary.
src/c/l/CleverHarold-0.1/harold/publishers/common.py CleverHarold(Download)
# ## from inspect import getargspec, getfile, getsource, ismodule from itertools import chain from os import path from sys import maxint
except (AttributeError, ):
pass
view_name = getfile(view)
if view_name == '<string>':
view_name = view.__name__
else:
if defaults:
extras = [load_template_flex(name, encoding, cache) for name in defaults]
extras = str.join(', ', ["'%s'" % getfile(name) for name in extras])
if repl:
repl = "%s, %s" % (repl, extras)
else:
src/g/a/gamera-HEAD/trunk/gamera/gamera/config.py gamera(Download)
from backport.config import *
from inspect import getfile
from os.path import split, join, expanduser
class GameraConfigOptionParser(ConfigOptionParser):
extra_files = []
def add_file(self, file):
self.extra_files.append(file)
def get_config_files(self):
dir = split(getfile(GameraConfigOptionParser))[0]
src/g/a/gamera-HEAD/gamera/gamera/config.py gamera(Download)
from backport.config import *
from inspect import getfile
from os.path import split, join, expanduser
class GameraConfigOptionParser(ConfigOptionParser):
extra_files = []
def add_file(self, file):
self.extra_files.append(file)
def get_config_files(self):
dir = split(getfile(GameraConfigOptionParser))[0]
src/p/y/pypy3-HEAD/pypy/module/__builtin__/functional.py pypy3(Download)
from pypy.rlib.rarithmetic import r_uint, intmask from pypy.rlib.objectmodel import specialize from pypy.module.__builtin__.app_functional import range as app_range from inspect import getsource, getfile """ Implementation of the common integer case of range. Instead of handling
src/p/y/pypy-HEAD/pypy/module/__builtin__/functional.py pypy(Download)
from pypy.rlib.rarithmetic import r_uint, intmask from pypy.rlib.objectmodel import specialize from pypy.module.__builtin__.app_functional import range as app_range from inspect import getsource, getfile """ Implementation of the common integer case of range. Instead of handling