本文整理匯總了Python中sys.__stdout__方法的典型用法代碼示例。如果您正苦於以下問題:Python sys.__stdout__方法的具體用法?Python sys.__stdout__怎麽用?Python sys.__stdout__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sys
的用法示例。
在下文中一共展示了sys.__stdout__方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testfile
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stdout__ [as 別名]
def testfile(self):
try:
with open(self.filename) as fd:
exec(compile(fd.read(), self.filename, 'exec'), {})
except KeyboardInterrupt:
raise RuntimeError('Keyboard interrupt')
except ImportError as ex:
module = ex.args[0].split()[-1].replace("'", '').split('.')[0]
if module in ['scipy', 'matplotlib', 'Scientific', 'lxml',
'flask', 'argparse']:
sys.__stdout__.write('skipped (no {0} module) '.format(module))
else:
raise
except NotAvailable as notavailable:
sys.__stdout__.write('skipped ')
msg = str(notavailable)
if msg:
sys.__stdout__.write('({0}) '.format(msg))
示例2: write
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stdout__ [as 別名]
def write(self,text):
proceed = 1
lineNo = 0
addText = ''
if self.func != None:
proceed,lineNo,newText = self.func(text)
if proceed:
if text.split() == []:
self.origOut.write(text)
else:
#if goint to stdout then only add line no file etc
#for stderr it is already there
if self.out:
if lineNo:
try:
raise "Dummy"
except:
newText = 'line('+str(sys.exc_info()[2].tb_frame.f_back.f_lineno)+'):'+newText
codeObject = sys.exc_info()[2].tb_frame.f_back.f_code
fileName = codeObject.co_filename
funcName = codeObject.co_name
self.origOut.write('file '+fileName+','+'func '+funcName+':')
self.origOut.write(newText)
#pass all other methods to __stdout__ so that we don't have to override them
示例3: __init__
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stdout__ [as 別名]
def __init__(self, stream, descriptions, verbosity):
super(EC2ApiTestResult, self).__init__()
self.stream = stream
self.showAll = verbosity > 1
self.num_slow_tests = 10
self.slow_tests = [] # this is a fixed-sized heap
self.colorizer = None
# NOTE(vish): reset stdout for the terminal check
stdout = sys.stdout
sys.stdout = sys.__stdout__
for colorizer in [_Win32Colorizer, _AnsiColorizer, _NullColorizer]:
if colorizer.supported():
self.colorizer = colorizer(self.stream)
break
sys.stdout = stdout
self.start_time = None
self.last_time = {}
self.results = {}
self.last_written = None
示例4: __init__
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stdout__ [as 別名]
def __init__(self, outfile=sys.__stdout__, backlog=False):
# get original stdout
self._orig_outfile = outfile
# just in case we wrap at runtime o the future,
# as we did with `colorama_wrapper` in the past
self.outfile = self._orig_outfile
# handle back logging
self._backlog = StringIO()
if backlog:
self._has_backlog = True
else:
self._has_backlog = False
# are colors supported ?
self._has_colors = ui.output.colors()
self._write_lock = False
示例5: find_pep8_errors
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stdout__ [as 別名]
def find_pep8_errors(cls, filename=None, lines=None):
try:
sys.stdout = cStringIO.StringIO()
config = {}
# Ignore long lines on test files, as the test names can get long
# when following our test naming standards.
if cls._is_test(filename):
config['ignore'] = ['E501']
checker = pep8.Checker(filename=filename, lines=lines,
**config)
checker.check_all()
output = sys.stdout.getvalue()
finally:
sys.stdout = sys.__stdout__
errors = []
for line in output.split('\n'):
parts = line.split(' ', 2)
if len(parts) == 3:
location, error, desc = parts
line_no = location.split(':')[1]
errors.append('%s ln:%s %s' % (error, line_no, desc))
return errors
示例6: quarterfinal
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stdout__ [as 別名]
def quarterfinal(FOLDER): # 讀取文件夾內的算法
PLRS = []
sys.path.append(os.path.abspath(FOLDER)) # 將AI文件夾加入環境路徑
for file in os.listdir(FOLDER):
if file.endswith('.py') and len(PLRS) < 8:
# 提取play函數
try:
name = file[:-3]
ai = __import__(name)
ai.play
PLRS.append((name, ai))
# 讀取時出錯
except Exception as e:
print('讀取%r時出錯:%s' % (file, e), file=sys.__stdout__)
return PLRS
# 四分之一決賽
示例7: quarterfinal
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stdout__ [as 別名]
def quarterfinal(FOLDER):# 讀取文件夾內的算法
PLRS = []
sys.path.append(os.path.abspath(FOLDER)) # 將AI文件夾加入環境路徑
for file in os.listdir(FOLDER):
if file.endswith('.py') and len(PLRS) < 2:
# 提取play函數
try:
name = file[:-3]
ai = __import__(name)
ai.play
PLRS.append((name, ai))
# 讀取時出錯
except Exception as e:
print('讀取%r時出錯:%s' % (file, e), file=sys.__stdout__)
return PLRS
# 半決賽
示例8: quarterfinal
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stdout__ [as 別名]
def quarterfinal(FOLDER):# 讀取文件夾內的算法
PLRS = []
sys.path.append(os.path.abspath(FOLDER)) # 將AI文件夾加入環境路徑
for file in os.listdir(FOLDER):
if file.endswith('.py') and len(PLRS) < 8:
# 提取play函數
try:
name = file[:-3]
ai = __import__(name)
ai.play
PLRS.append((name, ai))
# 讀取時出錯
except Exception as e:
print('讀取%r時出錯:%s' % (file, e), file=sys.__stdout__)
return PLRS
# 半決賽
示例9: cur_status
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stdout__ [as 別名]
def cur_status():
firstRowOfTable = [' ']
for i in range(len(players)):
firstRowOfTable += [players[i][0]]
x = PrettyTable(firstRowOfTable + ['Score'])
for i in range(len(players)):
x.add_row([players[i][0]] + boardRaw[i] + [board[i][4]])
x.add_row([' '] * (len(players) + 2))
os.system('clear')
print(x, file=sys.__stdout__)
# 積分條
out = sorted(board, key=itemgetter(-1, 1, 0), reverse=True)
for i in range(len(out)):
print(
'%15s%3d %s' % (out[i][0], out[i][-1], "----" * out[i][-1]),
file=sys.__stdout__)
示例10: execute_code
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stdout__ [as 別名]
def execute_code(cls, code):
""" Executes supplied code as pure python and returns a list of stdout, stderr
Args:
code (string): Python code to execute
Results:
(list): stdout, stderr of executed python code
Raises:
ExecutionError when supplied python is incorrect
Examples:
>>> execute_code('print "foobar"')
'foobar'
"""
output = StringIO.StringIO()
err = StringIO.StringIO()
sys.stdout = output
sys.stderr = err
try:
# pylint: disable=exec-used
exec(code)
# If the code is invalid, just skip the block - any actual code errors
# will be raised properly
except TypeError:
pass
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
results = list()
results.append(output.getvalue())
results.append(err.getvalue())
results = ''.join(results)
return results
示例11: Start
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stdout__ [as 別名]
def Start(self,func=None):
if self.out:
sys.stdout = self
self.origOut = sys.__stdout__
else:
sys.stderr= self
self.origOut = sys.__stderr__
if func:
self.func = func
else:
self.func = self.TestHook
#Stop will stop routing of print statements thru this class
示例12: Stop
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stdout__ [as 別名]
def Stop(self):
self.origOut.flush()
if self.out:
sys.stdout = sys.__stdout__
else:
sys.stderr = sys.__stderr__
self.func = None
#override write of stdout
示例13: _decode_stdoutdata
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stdout__ [as 別名]
def _decode_stdoutdata(stdoutdata):
""" Convert data read from stdout/stderr to unicode """
if not isinstance(stdoutdata, bytes):
return stdoutdata
encoding = getattr(sys.__stdout__, "encoding", locale.getpreferredencoding())
if encoding is None:
return stdoutdata.decode()
return stdoutdata.decode(encoding)
##########################################################################
# Import Stdlib Module
##########################################################################
示例14: __dir__
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stdout__ [as 別名]
def __dir__(self):
return dir(sys.__stdout__)
示例15: __getattribute__
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stdout__ [as 別名]
def __getattribute__(self, name):
if name == "__members__":
return dir(sys.__stdout__)
try:
stream = _local.stream
except AttributeError:
stream = sys.__stdout__
return getattr(stream, name)