本文整理汇总了Python中types.ModuleType.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python ModuleType.__init__方法的具体用法?Python ModuleType.__init__怎么用?Python ModuleType.__init__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类types.ModuleType
的用法示例。
在下文中一共展示了ModuleType.__init__方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: methods
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def methods():
if verbose: print "Testing methods..."
class C(object):
def __init__(self, x):
self.x = x
def foo(self):
return self.x
c1 = C(1)
vereq(c1.foo(), 1)
class D(C):
boo = C.foo
goo = c1.foo
d2 = D(2)
vereq(d2.foo(), 2)
vereq(d2.boo(), 2)
vereq(d2.goo(), 1)
class E(object):
foo = C.foo
vereq(E().foo, C.foo) # i.e., unbound
verify(repr(C.foo.__get__(C(1))).startswith("<bound method "))
示例2: funnynew
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def funnynew():
if verbose: print "Testing __new__ returning something unexpected..."
class C(object):
def __new__(cls, arg):
if isinstance(arg, str): return [1, 2, 3]
elif isinstance(arg, int): return object.__new__(D)
else: return object.__new__(cls)
class D(C):
def __init__(self, arg):
self.foo = arg
vereq(C("1"), [1, 2, 3])
vereq(D("1"), [1, 2, 3])
d = D(None)
veris(d.foo, None)
d = C(1)
vereq(isinstance(d, D), True)
vereq(d.foo, 1)
d = D(1)
vereq(isinstance(d, D), True)
vereq(d.foo, 1)
示例3: proxysuper
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def proxysuper():
if verbose:
print "Testing super() for a proxy object..."
class Proxy(object):
def __init__(self, obj):
self.__obj = obj
def __getattribute__(self, name):
if name.startswith("_Proxy__"):
return object.__getattribute__(self, name)
else:
return getattr(self.__obj, name)
class B(object):
def f(self):
return "B.f"
class C(B):
def f(self):
return super(C, self).f() + "->C.f"
obj = C()
p = Proxy(obj)
vereq(C.__dict__["f"](p), "B.f->C.f")
示例4: weakref_segfault
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def weakref_segfault():
# SF 742911
if verbose:
print "Testing weakref segfault..."
import weakref
class Provoker:
def __init__(self, referrent):
self.ref = weakref.ref(referrent)
def __del__(self):
x = self.ref()
class Oops(object):
pass
o = Oops()
o.whatever = Provoker(o)
del o
示例5: __init__
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def __init__(self, name, system_import):
ModuleType.__init__(self, name)
self._system_import = system_import
self._modules_to_patch = {}
示例6: __init__
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def __init__(self, realmod):
ModuleType.__init__(self, realmod.__name__, getattr(realmod, "__doc__", None))
object.__setattr__(self, "__realmod__", realmod)
object.__setattr__(self, "__file__", getattr(realmod, "__file__", None))
示例7: __init__
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def __init__(self, source):
modname = '%s.%s' % (_internalspace.__name__, source.spaceid)
ModuleType.__init__(self, modname)
self.__pluginbase_state__ = PluginBaseState(source)
示例8: __init__
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def __init__(self, name, attrmap, proxy=None):
ModuleType.__init__(self, name)
self.__attrmap = attrmap
self.__proxy = proxy
self.__log = logging.getLogger(name)
示例9: __init__
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def __init__(self, first, last):
self.first = first
self.last = last