本文整理汇总了Python中numpy.compat.py3k.basestring方法的典型用法代码示例。如果您正苦于以下问题:Python py3k.basestring方法的具体用法?Python py3k.basestring怎么用?Python py3k.basestring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.compat.py3k
的用法示例。
在下文中一共展示了py3k.basestring方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_command
# 需要导入模块: from numpy.compat import py3k [as 别名]
# 或者: from numpy.compat.py3k import basestring [as 别名]
def run_command(cmd, check_code=True):
""" Run command sequence `cmd` returning exit code, stdout, stderr
Parameters
----------
cmd : str or sequence
string with command name or sequence of strings defining command
check_code : {True, False}, optional
If True, raise error for non-zero return code
Returns
-------
returncode : int
return code from execution of `cmd`
stdout : bytes (python 3) or str (python 2)
stdout from `cmd`
stderr : bytes (python 3) or str (python 2)
stderr from `cmd`
Raises
------
RuntimeError
If `check_code` is True, and return code !=0
"""
cmd = [cmd] if isinstance(cmd, basestring) else list(cmd)
if os.name == 'nt':
# Quote any arguments with spaces. The quotes delimit the arguments
# on Windows, and the arguments might be file paths with spaces.
# On Unix the list elements are each separate arguments.
cmd = ['"{0}"'.format(c) if ' ' in c else c for c in cmd]
proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
if proc.poll() is None:
proc.terminate()
if check_code and proc.returncode != 0:
raise RuntimeError('\n'.join(
['Command "{0}" failed with',
'stdout', '------', '{1}', '',
'stderr', '------', '{2}']).format(cmd, stdout, stderr))
return proc.returncode, stdout, stderr
示例2: run_command
# 需要导入模块: from numpy.compat import py3k [as 别名]
# 或者: from numpy.compat.py3k import basestring [as 别名]
def run_command(cmd, check_code=True):
""" Run command sequence `cmd` returning exit code, stdout, stderr
Parameters
----------
cmd : str or sequence
string with command name or sequence of strings defining command
check_code : {True, False}, optional
If True, raise error for non-zero return code
Returns
-------
returncode : int
return code from execution of `cmd`
stdout : bytes (python 3) or str (python 2)
stdout from `cmd`
stderr : bytes (python 3) or str (python 2)
stderr from `cmd`
Raises
------
RuntimeError
If `check_code` is True, and return code !=0
"""
cmd = [cmd] if isinstance(cmd, basestring) else list(cmd)
if os.name == 'nt':
# Quote any arguments with spaces. The quotes delimit the arguments
# on Windows, and the arguments might be file paths with spaces.
# On Unix the list elements are each separate arguments.
cmd = ['"{0}"'.format(c) if ' ' in c else c for c in cmd]
proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
if proc.poll() == None:
proc.terminate()
if check_code and proc.returncode != 0:
raise RuntimeError('\n'.join(
['Command "{0}" failed with',
'stdout', '------', '{1}', '',
'stderr', '------', '{2}']).format(cmd, stdout, stderr))
return proc.returncode, stdout, stderr