概述
本文整理匯總了Python中os.environ.items方法的典型用法代碼示例。如果您正苦於以下問題:Python environ.items方法的具體用法?Python environ.items怎麽用?Python environ.items使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在模塊os.environ的用法示例。
在下文中一共展示了environ.items方法的17個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Python代碼示例。
示例1: submit_job
點讚 6
# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import items [as 別名]
def submit_job():
opts = [
["--{}".format(key[4:].replace("_", "-")), value]
for key, value in environ.items()
if key.startswith("TBV_") and key != "TBV_CLASS"
]
command = [
"spark-submit",
"--master", "yarn",
"--deploy-mode", "client",
"--class", environ["TBV_CLASS"],
artifact_file,
] + [v for opt in opts for v in opt if v]
call_exit_errors(command)
開發者ID:mozilla,項目名稱:telemetry-airflow,代碼行數:18,
示例2: cleanup
點讚 6
# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import items [as 別名]
def cleanup(self):
""" Removes temporary file. """
from os.path import exists
from os import remove
# return nodes to parent.
parent = None if self.parent is None else self.parent()
if parent is not None:
for key, value in self.machines.items():
if key in parent.machines:
parent.machines[key] += value
else:
parent.machines[key] = value
parent['n'] += self['n']
self.parent = None
self.machines = {}
self['n'] = 0
# remove nodefile, if it exists.
nodefile, self._nodefile = self._nodefile, None
if nodefile is not None and exists(nodefile):
try:
remove(nodefile)
except:
pass
開發者ID:pylada,項目名稱:pylada-light,代碼行數:25,
示例3: _preload_existing_vars
點讚 6
# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import items [as 別名]
def _preload_existing_vars(prefix: str) -> Store:
"""Preloads env vars from environ with the given prefix."""
if not prefix:
# If prefix is empty just return all the env variables.
return environ
prefixed = {}
# Prefix is not empty, do the search and replacement:
for env_name, env_value in environ.items():
if not env_name.startswith(prefix):
# Skip vars with no prefix.
continue
prefixed[env_name.replace(prefix, '', 1)] = env_value
return prefixed
開發者ID:sobolevn,項目名稱:dump-env,代碼行數:19,
示例4: compare_generic_iter
點讚 5
# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import items [as 別名]
def compare_generic_iter(make_it,match):
"""Utility to compare a generic 2.1/2.2+ iterator with an iterable
If running under Python 2.2+, this tests the iterator using iter()/next(),
as well as __getitem__. 'make_it' must be a function returning a fresh
iterator to be tested (since this may test the iterator twice)."""
it = make_it()
n = 0
for item in match:
if not it[n]==item: raise AssertionError
n+=1
try:
it[n]
except IndexError:
pass
else:
raise AssertionError("Too many items from __getitem__",it)
try:
iter, StopIteration
except NameError:
pass
else:
# Only test iter mode under 2.2+
it = make_it()
if not iter(it) is it: raise AssertionError
for item in match:
if not it.next()==item: raise AssertionError
try:
it.next()
except StopIteration:
pass
else:
raise AssertionError("Too many items from .next()",it)
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:37,
示例5: testMappingInterface
點讚 5
# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import items [as 別名]
def testMappingInterface(self):
test = [('x','y')]
self.assertEqual(len(Headers([])),0)
self.assertEqual(len(Headers(test[:])),1)
self.assertEqual(Headers(test[:]).keys(), ['x'])
self.assertEqual(Headers(test[:]).values(), ['y'])
self.assertEqual(Headers(test[:]).items(), test)
self.assertFalse(Headers(test).items() is test) # must be copy!
h=Headers([])
del h['foo'] # should not raise an error
h['Foo'] = 'bar'
for m in h.has_key, h.__contains__, h.get, h.get_all, h.__getitem__:
self.assertTrue(m('foo'))
self.assertTrue(m('Foo'))
self.assertTrue(m('FOO'))
self.assertFalse(m('bar'))
self.assertEqual(h['foo'],'bar')
h['foo'] = 'baz'
self.assertEqual(h['FOO'],'baz')
self.assertEqual(h.get_all('foo'),['baz'])
self.assertEqual(h.get("foo","whee"), "baz")
self.assertEqual(h.get("zoo","whee"), "whee")
self.assertEqual(h.setdefault("foo","whee"), "baz")
self.assertEqual(h.setdefault("zoo","whee"), "whee")
self.assertEqual(h["foo"],"baz")
self.assertEqual(h["zoo"],"whee")
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:32,
示例6: checkOSEnviron
點讚 5
# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import items [as 別名]
def checkOSEnviron(self,handler):
empty = {}; setup_testing_defaults(empty)
env = handler.environ
from os import environ
for k,v in environ.items():
if k not in empty:
self.assertEqual(env[k],v)
for k,v in empty.items():
self.assertIn(k, env)
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:11,
示例7: testMappingInterface
點讚 5
# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import items [as 別名]
def testMappingInterface(self):
test = [('x','y')]
self.assertEqual(len(Headers([])),0)
self.assertEqual(len(Headers(test[:])),1)
self.assertEqual(Headers(test[:]).keys(), ['x'])
self.assertEqual(Headers(test[:]).values(), ['y'])
self.assertEqual(Headers(test[:]).items(), test)
self.assertIsNot(Headers(test).items(), test) # must be copy!
h=Headers([])
del h['foo'] # should not raise an error
h['Foo'] = 'bar'
for m in h.has_key, h.__contains__, h.get, h.get_all, h.__getitem__:
self.assertTrue(m('foo'))
self.assertTrue(m('Foo'))
self.assertTrue(m('FOO'))
self.assertFalse(m('bar'))
self.assertEqual(h['foo'],'bar')
h['foo'] = 'baz'
self.assertEqual(h['FOO'],'baz')
self.assertEqual(h.get_all('foo'),['baz'])
self.assertEqual(h.get("foo","whee"), "baz")
self.assertEqual(h.get("zoo","whee"), "whee")
self.assertEqual(h.setdefault("foo","whee"), "baz")
self.assertEqual(h.setdefault("zoo","whee"), "whee")
self.assertEqual(h["foo"],"baz")
self.assertEqual(h["zoo"],"whee")
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:32,
示例8: do_GET
點讚 5
# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import items [as 別名]
def do_GET(s):
s.send_response(200)
s.send_header("content-type", "text/json")
s.end_headers()
s.wfile.write(dumps(environ.items()))
s.wfile.close()
開發者ID:ClusterHQ,項目名稱:flocker,代碼行數:8,
示例9: compare_generic_iter
點讚 5
# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import items [as 別名]
def compare_generic_iter(make_it,match):
"""Utility to compare a generic 2.1/2.2+ iterator with an iterable
If running under Python 2.2+, this tests the iterator using iter()/next(),
as well as __getitem__. 'make_it' must be a function returning a fresh
iterator to be tested (since this may test the iterator twice)."""
it = make_it()
n = 0
for item in match:
if not it[n]==item: raise AssertionError
n+=1
try:
it[n]
except IndexError:
pass
else:
raise AssertionError("Too many items from __getitem__",it)
try:
iter, StopIteration
except NameError:
pass
else:
# Only test iter mode under 2.2+
it = make_it()
if not iter(it) is it: raise AssertionError
for item in match:
if not next(it) == item: raise AssertionError
try:
next(it)
except StopIteration:
pass
else:
raise AssertionError("Too many items from .__next__()", it)
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:37,
示例10: testMappingInterface
點讚 5
# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import items [as 別名]
def testMappingInterface(self):
test = [('x','y')]
self.assertEqual(len(Headers()), 0)
self.assertEqual(len(Headers([])),0)
self.assertEqual(len(Headers(test[:])),1)
self.assertEqual(Headers(test[:]).keys(), ['x'])
self.assertEqual(Headers(test[:]).values(), ['y'])
self.assertEqual(Headers(test[:]).items(), test)
self.assertIsNot(Headers(test).items(), test) # must be copy!
h = Headers()
del h['foo'] # should not raise an error
h['Foo'] = 'bar'
for m in h.__contains__, h.get, h.get_all, h.__getitem__:
self.assertTrue(m('foo'))
self.assertTrue(m('Foo'))
self.assertTrue(m('FOO'))
self.assertFalse(m('bar'))
self.assertEqual(h['foo'],'bar')
h['foo'] = 'baz'
self.assertEqual(h['FOO'],'baz')
self.assertEqual(h.get_all('foo'),['baz'])
self.assertEqual(h.get("foo","whee"), "baz")
self.assertEqual(h.get("zoo","whee"), "whee")
self.assertEqual(h.setdefault("foo","whee"), "baz")
self.assertEqual(h.setdefault("zoo","whee"), "whee")
self.assertEqual(h["foo"],"baz")
self.assertEqual(h["zoo"],"whee")
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:33,
示例11: testMappingInterface
點讚 5
# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import items [as 別名]
def testMappingInterface(self):
test = [('x','y')]
self.assertEqual(len(Headers([])),0)
self.assertEqual(len(Headers(test[:])),1)
self.assertEqual(Headers(test[:]).keys(), ['x'])
self.assertEqual(Headers(test[:]).values(), ['y'])
self.assertEqual(Headers(test[:]).items(), test)
self.assertIsNot(Headers(test).items(), test) # must be copy!
h=Headers([])
del h['foo'] # should not raise an error
h['Foo'] = 'bar'
for m in h.__contains__, h.get, h.get_all, h.__getitem__:
self.assertTrue(m('foo'))
self.assertTrue(m('Foo'))
self.assertTrue(m('FOO'))
self.assertFalse(m('bar'))
self.assertEqual(h['foo'],'bar')
h['foo'] = 'baz'
self.assertEqual(h['FOO'],'baz')
self.assertEqual(h.get_all('foo'),['baz'])
self.assertEqual(h.get("foo","whee"), "baz")
self.assertEqual(h.get("zoo","whee"), "whee")
self.assertEqual(h.setdefault("foo","whee"), "baz")
self.assertEqual(h.setdefault("zoo","whee"), "whee")
self.assertEqual(h["foo"],"baz")
self.assertEqual(h["zoo"],"whee")
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:32,
示例12: __new__
點讚 5
# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import items [as 別名]
def __new__(cls) -> "Configuration":
if cls._instance is not None:
instance = cls._instance
else:
instance = super().__new__(cls)
for key, value_str in environ.items():
match = fullmatch(
r"OPENTELEMETRY_PYTHON_([A-Za-z_][w_]*)", key
)
if match is not None:
key = match.group(1)
value = value_str # type: ConfigValue
if value_str == "True":
value = True
elif value_str == "False":
value = False
else:
try:
value = int(value_str)
except ValueError:
pass
try:
value = float(value_str)
except ValueError:
pass
instance._config_map[key] = value
cls._instance = instance
return instance
開發者ID:open-telemetry,項目名稱:opentelemetry-python,代碼行數:38,
示例13: _msvc14_get_vc_env
點讚 5
# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import items [as 別名]
def _msvc14_get_vc_env(plat_spec):
"""Python 3.8 "distutils/_msvccompiler.py" backport"""
if "DISTUTILS_USE_SDK" in environ:
return {
key.lower(): value
for key, value in environ.items()
}
vcvarsall, vcruntime = _msvc14_find_vcvarsall(plat_spec)
if not vcvarsall:
raise distutils.errors.DistutilsPlatformError(
"Unable to find vcvarsall.bat"
)
try:
out = subprocess.check_output(
'cmd /u /c "{}" {} && set'.format(vcvarsall, plat_spec),
stderr=subprocess.STDOUT,
).decode('utf-16le', errors='replace')
except subprocess.CalledProcessError as exc:
raise distutils.errors.DistutilsPlatformError(
"Error executing {}".format(exc.cmd)
) from exc
env = {
key.lower(): value
for key, _, value in
(line.partition('=') for line in out.splitlines())
if key and value
}
if vcruntime:
env['py_vcruntime_redist'] = vcruntime
return env
開發者ID:pypa,項目名稱:setuptools,代碼行數:36,
示例14: acquire
點讚 5
# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import items [as 別名]
def acquire(self, other, n=None):
""" Acquires the processes from another communicator.
Use at your risk... Family lines could become tangled, eg to which
communicator will the processes return when self is destroyed? In
practice, it will return to the parent of self. Is that what you want?
The processes in other are acquired by self. If n is not None, only n
processes are acquired, up to the maximum number of processes in other.
If n is None, then all processes are acquired.
As always, processes are exclusive owned exclusively. Processes
acquired by self are no longuer in other.
"""
if self._nodefile is not None or other._nodefile is not None:
raise NodeFileExists("Comm already used in other process.")
if n is not None:
comm = other.lend(n)
self.acquire(comm)
return
for key, value in other.machines.items():
if key in self.machines:
self.machines[key] += value
else:
self.machines[key] = value
self['n'] += other['n']
other.machines = {}
other['n'] = 0
other.parent = None
other.cleanup()
開發者ID:pylada,項目名稱:pylada-light,代碼行數:32,
示例15: nodefile
點讚 5
# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import items [as 別名]
def nodefile(self, dir=None):
""" Returns name of temporary nodefile.
This file should be cleaned up once the mpi process is finished by
calling :py:meth:`~Communicator.cleanup`. It is an error to call this
function without first cleaning up. Since only one mpi process should
be attached to a communicator, this makes sense.
"""
from tempfile import NamedTemporaryFile
from ..misc import RelativePath
from ..process import logger
if self._nodefile is not None:
logger.debug('process/mpi.py: old nodefile: %s' % self._nodefile)
raise NodeFileExists("Please call cleanup first. nodefile: "%s""
% (self._nodefile, ))
if self['n'] == 0:
raise MPISizeError("No processes in this communicator.")
with NamedTemporaryFile(
dir=RelativePath(dir).path, delete=False,
prefix='pylada_comm') as file:
logger.debug('process/mpi.py: new nodefile: %s' % file.name)
for machine, slots in self.machines.items():
if slots == 0:
continue
##file.write('{0} slots={1}n'.format(machine, slots))
file.write(machine)
file.write('n')
logger.debug('machine: %s slots: %s' % (machine, slots))
self._nodefile = file.name
return self._nodefile
開發者ID:pylada,項目名稱:pylada-light,代碼行數:35,
示例16: testMappingInterface
點讚 5
# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import items [as 別名]
def testMappingInterface(self):
test = [('x','y')]
self.assertEqual(len(Headers([])),0)
self.assertEqual(len(Headers(test[:])),1)
self.assertEqual(Headers(test[:]).keys(), ['x'])
self.assertEqual(Headers(test[:]).values(), ['y'])
self.assertEqual(Headers(test[:]).items(), test)
self.failIf(Headers(test).items() is test) # must be copy!
h=Headers([])
del h['foo'] # should not raise an error
h['Foo'] = 'bar'
for m in h.has_key, h.__contains__, h.get, h.get_all, h.__getitem__:
self.failUnless(m('foo'))
self.failUnless(m('Foo'))
self.failUnless(m('FOO'))
self.failIf(m('bar'))
self.assertEqual(h['foo'],'bar')
h['foo'] = 'baz'
self.assertEqual(h['FOO'],'baz')
self.assertEqual(h.get_all('foo'),['baz'])
self.assertEqual(h.get("foo","whee"), "baz")
self.assertEqual(h.get("zoo","whee"), "whee")
self.assertEqual(h.setdefault("foo","whee"), "baz")
self.assertEqual(h.setdefault("zoo","whee"), "whee")
self.assertEqual(h["foo"],"baz")
self.assertEqual(h["zoo"],"whee")
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:32,
示例17: checkOSEnviron
點讚 5
# 需要導入模塊: from os import environ [as 別名]
# 或者: from os.environ import items [as 別名]
def checkOSEnviron(self,handler):
empty = {}; setup_testing_defaults(empty)
env = handler.environ
from os import environ
for k,v in environ.items():
if not empty.has_key(k):
self.assertEqual(env[k],v)
for k,v in empty.items():
self.failUnless(env.has_key(k))
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:11,
注:本文中的os.environ.items方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。
最后
以上就是精明芒果为你收集整理的pythonitems方法_Python environ.items方法代碼示例的全部内容,希望文章能够帮你解决pythonitems方法_Python environ.items方法代碼示例所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复