本文整理匯總了Python中__builtin__.object方法的典型用法代碼示例。如果您正苦於以下問題:Python __builtin__.object方法的具體用法?Python __builtin__.object怎麽用?Python __builtin__.object使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類__builtin__
的用法示例。
在下文中一共展示了__builtin__.object方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: locate
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import object [as 別名]
def locate(path, forceload=0):
"""Locate an object by name or dotted path, importing as necessary."""
parts = [part for part in split(path, '.') if part]
module, n = None, 0
while n < len(parts):
nextmodule = safeimport(join(parts[:n+1], '.'), forceload)
if nextmodule: module, n = nextmodule, n + 1
else: break
if module:
object = module
for part in parts[n:]:
try: object = getattr(object, part)
except AttributeError: return None
return object
else:
if hasattr(__builtin__, path):
return getattr(__builtin__, path)
# --------------------------------------- interactive interpreter interface
示例2: render_doc
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import object [as 別名]
def render_doc(thing, title='Python Library Documentation: %s', forceload=0):
"""Render text documentation, given an object or a path to an object."""
object, name = resolve(thing, forceload)
desc = describe(object)
module = inspect.getmodule(object)
if name and '.' in name:
desc += ' in ' + name[:name.rfind('.')]
elif module and module is not object:
desc += ' in module ' + module.__name__
if type(object) is _OLD_INSTANCE_TYPE:
# If the passed object is an instance of an old-style class,
# document its available methods instead of its value.
object = object.__class__
elif not (inspect.ismodule(object) or
inspect.isclass(object) or
inspect.isroutine(object) or
inspect.isgetsetdescriptor(object) or
inspect.ismemberdescriptor(object) or
isinstance(object, property)):
# If the passed object is a piece of data or an instance,
# document its available methods instead of its value.
object = type(object)
desc += ' object'
return title % desc + '\n\n' + text.document(object, name)
示例3: locate
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import object [as 別名]
def locate(path, forceload=0):
"""Locate an object by name or dotted path, importing as necessary."""
parts = [part for part in split(path, '.') if part]
module, n = None, 0
while n < len(parts):
nextmodule = safeimport(join(parts[:n+1], '.'), forceload)
if nextmodule: module, n = nextmodule, n + 1
else: break
if module:
object = module
else:
object = __builtin__
for part in parts[n:]:
try:
object = getattr(object, part)
except AttributeError:
return None
return object
# --------------------------------------- interactive interpreter interface
示例4: _is_bytes_like
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import object [as 別名]
def _is_bytes_like(obj):
"""
Check whether obj behaves like a bytes object.
"""
try:
obj + b''
except (TypeError, ValueError):
return False
return True
示例5: getdoc
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import object [as 別名]
def getdoc(object):
"""Get the doc string or comments for an object."""
result = inspect.getdoc(object) or inspect.getcomments(object)
return result and re.sub('^ *\n', '', rstrip(result)) or ''
示例6: classname
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import object [as 別名]
def classname(object, modname):
"""Get a class name and qualify it with a module name if necessary."""
name = object.__name__
if object.__module__ != modname:
name = object.__module__ + '.' + name
return name
示例7: isdata
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import object [as 別名]
def isdata(object):
"""Check if an object is of a type that probably means it's data."""
return not (inspect.ismodule(object) or inspect.isclass(object) or
inspect.isroutine(object) or inspect.isframe(object) or
inspect.istraceback(object) or inspect.iscode(object))
示例8: stripid
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import object [as 別名]
def stripid(text):
"""Remove the hexadecimal id from a Python object representation."""
# The behaviour of %p is implementation-dependent in terms of case.
return _re_stripid.sub(r'\1', text)
示例9: classify_class_attrs
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import object [as 別名]
def classify_class_attrs(object):
"""Wrap inspect.classify_class_attrs, with fixup for data descriptors."""
def fixup(data):
name, kind, cls, value = data
if inspect.isdatadescriptor(value):
kind = 'data descriptor'
return name, kind, cls, value
return map(fixup, inspect.classify_class_attrs(object))
# ----------------------------------------------------- module manipulation
示例10: fail
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import object [as 別名]
def fail(self, object, name=None, *args):
"""Raise an exception for unimplemented types."""
message = "don't know how to document object%s of type %s" % (
name and ' ' + repr(name), type(object).__name__)
raise TypeError, message
示例11: getdocloc
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import object [as 別名]
def getdocloc(self, object):
"""Return the location of module docs or None"""
try:
file = inspect.getabsfile(object)
except TypeError:
file = '(built-in)'
docloc = os.environ.get("PYTHONDOCS",
"http://docs.python.org/library")
basedir = os.path.join(sys.exec_prefix, "lib",
"python"+sys.version[0:3])
if (isinstance(object, type(os)) and
(object.__name__ in ('errno', 'exceptions', 'gc', 'imp',
'marshal', 'posix', 'signal', 'sys',
'thread', 'zipimport') or
(file.startswith(basedir) and
not file.startswith(os.path.join(basedir, 'site-packages')))) and
object.__name__ not in ('xml.etree', 'test.pydoc_mod')):
if docloc.startswith("http://"):
docloc = "%s/%s" % (docloc.rstrip("/"), object.__name__)
else:
docloc = os.path.join(docloc, object.__name__ + ".html")
else:
docloc = None
return docloc
# -------------------------------------------- HTML documentation generator
示例12: repr
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import object [as 別名]
def repr(self, object):
return Repr.repr(self, object)
示例13: classlink
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import object [as 別名]
def classlink(self, object, modname):
"""Make a link for a class."""
name, module = object.__name__, sys.modules.get(object.__module__)
if hasattr(module, name) and getattr(module, name) is object:
return '<a href="%s.html#%s">%s</a>' % (
module.__name__, name, classname(object, modname))
return classname(object, modname)
示例14: modulelink
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import object [as 別名]
def modulelink(self, object):
"""Make a link for a module."""
return '<a href="%s.html">%s</a>' % (object.__name__, object.__name__)
示例15: formatvalue
# 需要導入模塊: import __builtin__ [as 別名]
# 或者: from __builtin__ import object [as 別名]
def formatvalue(self, object):
"""Format an argument default value as text."""
return self.grey('=' + self.repr(object))