本文整理匯總了Python中sys.__dict__方法的典型用法代碼示例。如果您正苦於以下問題:Python sys.__dict__方法的具體用法?Python sys.__dict__怎麽用?Python sys.__dict__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sys
的用法示例。
在下文中一共展示了sys.__dict__方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: finalize_options
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __dict__ [as 別名]
def finalize_options(self):
self.set_undefined_options('install_lib',
('install_dir', 'install_dir'))
self.set_undefined_options('install',('install_layout','install_layout'))
if sys.hexversion > 0x2060000:
self.set_undefined_options('install',('prefix_option','prefix_option'))
ei_cmd = self.get_finalized_command("egg_info")
basename = pkg_resources.Distribution(
None, None, ei_cmd.egg_name, ei_cmd.egg_version
).egg_name() + '.egg-info'
if self.install_layout:
if not self.install_layout.lower() in ['deb']:
raise DistutilsOptionError("unknown value for --install-layout")
self.install_layout = self.install_layout.lower()
basename = basename.replace('-py%s' % pkg_resources.PY_MAJOR, '')
elif self.prefix_option or 'real_prefix' in sys.__dict__:
# don't modify for virtualenv
pass
else:
basename = basename.replace('-py%s' % pkg_resources.PY_MAJOR, '')
self.source = ei_cmd.egg_info
self.target = os.path.join(self.install_dir, basename)
self.outputs = []
示例2: _reset_py_display
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __dict__ [as 別名]
def _reset_py_display() -> None:
"""
Resets the dynamic objects in the sys module that the py and ipy consoles fight over.
When a Python console starts it adopts certain display settings if they've already been set.
If an ipy console has previously been run, then py uses its settings and ends up looking
like an ipy console in terms of prompt and exception text. This method forces the Python
console to create its own display settings since they won't exist.
IPython does not have this problem since it always overwrites the display settings when it
is run. Therefore this method only needs to be called before creating a Python console.
"""
# Delete any prompts that have been set
attributes = ['ps1', 'ps2', 'ps3']
for cur_attr in attributes:
try:
del sys.__dict__[cur_attr]
except KeyError:
pass
# Reset functions
sys.displayhook = sys.__displayhook__
sys.excepthook = sys.__excepthook__
示例3: test_type_relation
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __dict__ [as 別名]
def test_type_relation(self):
name = 'T'
base = object
bases = (base,)
dict = {'__slots__': ('a', 'b')}
T = type(name, bases, dict)
# tp_dict can't be directly tested since .__dict__ returns a proxy
# and the dict passed is not used directly.
# We test it indirectly by getting a path through it.
self.chkpath(T, T.a, "%s.__dict__['a']")
# The C-struct __slots__ field can't be tested directly
# This just tests the ordinary attribute
self.chkpath(T, T.__slots__, "%s.__dict__['__slots__']")
self.chkrelattr(T, '__mro__', '__base__', '__bases__')
# tp_cache and tp_subclasses can also not be tested directly
# Inheritance is tested via test_object_relation()
示例4: warn
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __dict__ [as 別名]
def warn(message, category=None, stacklevel=1):
"""Issue a warning, or maybe ignore it or raise an exception."""
# Check if message is already a Warning object
if isinstance(message, Warning):
category = message.__class__
# Check category argument
if category is None:
category = UserWarning
assert issubclass(category, Warning)
# Get context information
try:
caller = sys._getframe(stacklevel)
except ValueError:
globals = sys.__dict__
lineno = 1
else:
globals = caller.f_globals
lineno = caller.f_lineno
if '__name__' in globals:
module = globals['__name__']
else:
module = "<string>"
filename = globals.get('__file__')
if filename:
fnl = filename.lower()
if fnl.endswith((".pyc", ".pyo")):
filename = filename[:-1]
else:
if module == "__main__":
try:
filename = sys.argv[0]
except AttributeError:
# embedded interpreters don't have sys.argv, see bug #839151
filename = '__main__'
if not filename:
filename = module
registry = globals.setdefault("__warningregistry__", {})
warn_explicit(message, category, filename, lineno, module, registry,
globals)
示例5: _expand
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __dict__ [as 別名]
def _expand(self, *attrs):
config_vars = self.get_finalized_command('install').config_vars
if self.prefix or self.install_layout:
if self.install_layout and self.install_layout in ['deb']:
scheme_name = "deb_system"
self.prefix = '/usr'
elif self.prefix or 'real_prefix' in sys.__dict__:
scheme_name = os.name
else:
scheme_name = "posix_local"
# Set default install_dir/scripts from --prefix
config_vars = config_vars.copy()
config_vars['base'] = self.prefix
scheme = self.INSTALL_SCHEMES.get(scheme_name,self.DEFAULT_SCHEME)
for attr, val in scheme.items():
if getattr(self, attr, None) is None:
setattr(self, attr, val)
from distutils.util import subst_vars
for attr in attrs:
val = getattr(self, attr)
if val is not None:
val = subst_vars(val, config_vars)
if os.name == 'posix':
val = os.path.expanduser(val)
setattr(self, attr, val)
示例6: _get_default_scheme
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __dict__ [as 別名]
def _get_default_scheme():
if os.name == 'posix':
# the default scheme for posix on Debian/Ubuntu is posix_local
# FIXME: return dist-packages/posix_prefix only for
# is_default_prefix and 'PYTHONUSERBASE' not in os.environ and 'real_prefix' not in sys.__dict__
# is_default_prefix = not prefix or os.path.normpath(prefix) in ('/usr', '/usr/local')
return 'posix_local'
return os.name
示例7: __subclasshook__
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __dict__ [as 別名]
def __subclasshook__(cls, C):
if cls is Collection:
if any("__len__" in B.__dict__ for B in C.__mro__) and \
any("__iter__" in B.__dict__ for B in C.__mro__) and \
any("__contains__" in B.__dict__ for B in C.__mro__):
return True
return NotImplemented
# Python 3.4 require contextlib2 for temporarily redirecting stderr and stdout
示例8: test_dictproxy_relation
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __dict__ [as 別名]
def test_dictproxy_relation(self):
v1 = 'v1'
class T(object):
k1 = v1
x = T.__dict__
self.chkpath(x, v1, "%s->mapping['k1']")
self.chkrel(x, v1, "%s['k1']")
示例9: test_function_relation
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __dict__ [as 別名]
def test_function_relation(self):
def f(x, y=3):
return self
f.a = []
self.chkrelattr(f, '__code__', '__globals__', '__defaults__',
'__closure__', '__doc__', '__name__', '__dict__',
'a')
示例10: test_module_relation
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __dict__ [as 別名]
def test_module_relation(self):
self.chkrelattr(unittest, '__dict__', 'TestCase')
示例11: warn
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __dict__ [as 別名]
def warn(msg, stacklevel=1, function=None):
if function is not None:
filename = py.std.inspect.getfile(function)
lineno = py.code.getrawcode(function).co_firstlineno
else:
try:
caller = sys._getframe(stacklevel)
except ValueError:
globals = sys.__dict__
lineno = 1
else:
globals = caller.f_globals
lineno = caller.f_lineno
if '__name__' in globals:
module = globals['__name__']
else:
module = "<string>"
filename = globals.get('__file__')
if filename:
fnl = filename.lower()
if fnl.endswith(".pyc") or fnl.endswith(".pyo"):
filename = filename[:-1]
elif fnl.endswith("$py.class"):
filename = filename.replace('$py.class', '.py')
else:
if module == "__main__":
try:
filename = sys.argv[0]
except AttributeError:
# embedded interpreters don't have sys.argv, see bug #839151
filename = '__main__'
if not filename:
filename = module
path = py.path.local(filename)
warning = DeprecationWarning(msg, path, lineno)
py.std.warnings.warn_explicit(warning, category=Warning,
filename=str(warning.path),
lineno=warning.lineno,
registry=py.std.warnings.__dict__.setdefault(
"__warningsregistry__", {})
)
示例12: warn
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __dict__ [as 別名]
def warn(message, category=None, stacklevel=1):
"""Issue a warning, or maybe ignore it or raise an exception."""
# Check if message is already a Warning object
if isinstance(message, Warning):
category = message.__class__
# Check category argument
if category is None:
category = UserWarning
assert issubclass(category, Warning)
# Get context information
try:
caller = sys._getframe(stacklevel)
except ValueError:
globals = sys.__dict__
lineno = 1
else:
globals = caller.f_globals
lineno = caller.f_lineno
if '__name__' in globals:
module = globals['__name__']
else:
module = "<string>"
filename = globals.get('__file__')
if filename:
fnl = filename.lower()
if fnl.endswith(".pyc") or fnl.endswith(".pyo"):
filename = filename[:-1]
else:
if module == "__main__":
filename = sys.argv[0]
if not filename:
filename = module
registry = globals.setdefault("__warningregistry__", {})
warn_explicit(message, category, filename, lineno, module, registry)
示例13: __getstate__
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __dict__ [as 別名]
def __getstate__(self):
# Frequently a tree builder can't be pickled.
d = dict(self.__dict__)
if 'builder' in d and not self.builder.picklable:
d['builder'] = None
return d
示例14: warn
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __dict__ [as 別名]
def warn(message, category=None, stacklevel=1):
"""Issue a warning, or maybe ignore it or raise an exception."""
# Check if message is already a Warning object
if isinstance(message, Warning):
category = message.__class__
# Check category argument
if category is None:
category = UserWarning
assert issubclass(category, Warning)
# Get context information
try:
caller = sys._getframe(stacklevel)
except ValueError:
globals = sys.__dict__
lineno = 1
else:
globals = caller.f_globals
lineno = caller.f_lineno
if '__name__' in globals:
module = globals['__name__']
else:
module = "<string>"
filename = globals.get('__file__')
if filename:
fnl = filename.lower()
if fnl.endswith((".pyc", ".pyo")):
filename = filename[:-1]
elif fnl.endswith("$py.class"):
filename = filename[:-9] + '.py'
else:
if module == "__main__":
try:
filename = sys.argv[0]
except AttributeError:
# embedded interpreters don't have sys.argv, see bug #839151
filename = '__main__'
if not filename:
filename = module
registry = globals.setdefault("__warningregistry__", {})
warn_explicit(message, category, filename, lineno, module, registry,
globals)