當前位置: 首頁>>代碼示例>>Python>>正文


Python sys.stdout方法代碼示例

本文整理匯總了Python中sys.stdout方法的典型用法代碼示例。如果您正苦於以下問題:Python sys.stdout方法的具體用法?Python sys.stdout怎麽用?Python sys.stdout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sys的用法示例。


在下文中一共展示了sys.stdout方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: stats

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import stdout [as 別名]
def stats(self, filename, sortby='cumulative'):
        """:rtype stats(index): output of print_stats() for the given profile.
        """
        sio = io.StringIO()
        if sys.version_info >= (2, 5):
            s = pstats.Stats(os.path.join(self.path, filename), stream=sio)
            s.strip_dirs()
            s.sort_stats(sortby)
            s.print_stats()
        else:
            # pstats.Stats before Python 2.5 didn't take a 'stream' arg,
            # but just printed to stdout. So re-route stdout.
            s = pstats.Stats(os.path.join(self.path, filename))
            s.strip_dirs()
            s.sort_stats(sortby)
            oldout = sys.stdout
            try:
                sys.stdout = sio
                s.print_stats()
            finally:
                sys.stdout = oldout
        response = sio.getvalue()
        sio.close()
        return response 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:26,代碼來源:profiler.py

示例2: supervisor_events

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import stdout [as 別名]
def supervisor_events(stdin, stdout):
    """
    An event stream from Supervisor.
    """

    while True:
        stdout.write('READY\n')
        stdout.flush()

        line = stdin.readline()
        headers = get_headers(line)

        payload = stdin.read(int(headers['len']))
        event_headers, event_data = eventdata(payload)

        yield event_headers, event_data

        stdout.write('RESULT 2\nOK')
        stdout.flush() 
開發者ID:infoxchange,項目名稱:supervisor-logging,代碼行數:21,代碼來源:__init__.py

示例3: test_list_agents

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import stdout [as 別名]
def test_list_agents(self):
        announce('test_list_agents')
        report = True
        orig_out = sys.stdout
        sys.stdout = open("checkfile.txt", "w")
        self.env.list_agents()
        sys.stdout.close()
        sys.stdout = orig_out
        f = open("checkfile.txt", "r")
        line1 = f.readline()

        for agent in self.env.agents:
            line = f.readline()
            line_list = line.split(" with a goal of ")

            line_list[1] = line_list[1].strip()
            if agent.name != line_list[0] or agent.goal != line_list[1]:
                report = False
                break
        f.close()
        os.remove("checkfile.txt")
        self.assertEqual(report, True) 
開發者ID:gcallah,項目名稱:indras_net,代碼行數:24,代碼來源:test_basic.py

示例4: test_list_agents

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import stdout [as 別名]
def test_list_agents(self):
        announce('test_list_agents')
        report = True
        orig_out = sys.stdout
        sys.stdout = open("checkfile.txt", "w")
        self.env.list_agents()
        sys.stdout.close()
        sys.stdout = orig_out
        f = open("checkfile.txt", "r")
        f.readline()

        for agent in self.env.agents:
            line = f.readline()
            line_list = line.split(" with a goal of ")

            line_list[1] = line_list[1].strip()
            if agent.name != line_list[0] or agent.goal != line_list[1]:
                report = False
                break
        f.close()
        os.remove("checkfile.txt")
        self.assertEqual(report, True) 
開發者ID:gcallah,項目名稱:indras_net,代碼行數:24,代碼來源:test_hiv.py

示例5: __init__

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import stdout [as 別名]
def __init__(self, name=""):
        self.barsToProgress = {}

        self.t0 = time.time()
        self.timeRemaining = "--"
        self.status = "+"
        self.name = name
        self.lastRedraw = time.time()
        self.isatty = sys.stdout.isatty()

        try:
            self.handleResize(None,None)
            signal.signal(signal.SIGWINCH, self.handleResize)
            self.signal_set = True
        except:
            self.term_width = 79 
開發者ID:svviz,項目名稱:svviz,代碼行數:18,代碼來源:multiprocessor.py

示例6: getLogger

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import stdout [as 別名]
def getLogger(fname=None):
    format='%(asctime)s:%(process)d:%(threadName)s:%(levelname)s:%(name)s:%(pathname)s %(lineno)d:%(message)s'
    formatter = MyFormatter(format)

    logger = logging.getLogger('sdx')

    if fname:
        fh = logging.FileHandler(fname)
        fh.setFormatter(formatter)
        logger.addHandler(fh)

    ch = logging.StreamHandler(stream=sys.stdout)
    ch.setFormatter(formatter)
    logger.addHandler(ch)

    return logger 
開發者ID:sdn-ixp,項目名稱:iSDX,代碼行數:18,代碼來源:logServer.py

示例7: _receiver

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import stdout [as 別名]
def _receiver(conn,stdout):

    while True:
        try:
            line = conn.recv()

            if line == "":
                continue

            _write(stdout, line)
            ''' example: announce route 1.2.3.4 next-hop 5.6.7.8 as-path [ 100 200 ] '''

            recvLogger.debug(line)

        except:
            pass 
開發者ID:sdn-ixp,項目名稱:iSDX,代碼行數:18,代碼來源:client.py

示例8: pipe_fopen

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import stdout [as 別名]
def pipe_fopen(command, mode, background=True):
    if mode not in ["rb", "r"]:
        raise RuntimeError("Now only support input from pipe")

    p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)

    def background_command_waiter(command, p):
        p.wait()
        if p.returncode != 0:
            warnings.warn("Command \"{0}\" exited with status {1}".format(
                command, p.returncode))
            _thread.interrupt_main()

    if background:
        thread = threading.Thread(target=background_command_waiter,
                                  args=(command, p))
        # exits abnormally if main thread is terminated .
        thread.daemon = True
        thread.start()
    else:
        background_command_waiter(command, p)
    return p.stdout 
開發者ID:funcwj,項目名稱:kaldi-python-io,代碼行數:24,代碼來源:inst.py

示例9: _fopen

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import stdout [as 別名]
def _fopen(fname, mode):
    """
    Extend file open function, to support 
        1) "-", which means stdin/stdout
        2) "$cmd |" which means pipe.stdout
    """
    if mode not in ["w", "r", "wb", "rb"]:
        raise ValueError("Unknown open mode: {mode}".format(mode=mode))
    if not fname:
        return None
    fname = fname.rstrip()
    if fname == "-":
        if mode in ["w", "wb"]:
            return sys.stdout.buffer if mode == "wb" else sys.stdout
        else:
            return sys.stdin.buffer if mode == "rb" else sys.stdin
    elif fname[-1] == "|":
        pin = pipe_fopen(fname[:-1], mode, background=(mode == "rb"))
        return pin if mode == "rb" else TextIOWrapper(pin)
    else:
        if mode in ["r", "rb"] and not os.path.exists(fname):
            raise FileNotFoundError(
                "Could not find common file: {}".format(fname))
        return open(fname, mode) 
開發者ID:funcwj,項目名稱:kaldi-python-io,代碼行數:26,代碼來源:inst.py

示例10: call_command

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import stdout [as 別名]
def call_command():
    from django.core.management import call_command

    class CallCommand(object):
        def __init__(self):
            self.io = BytesIO()

        def __call__(self, *args, **kwargs):
            self.io = BytesIO()
            stdout = sys.stdout
            try:
                sys.stdout = self.io
                call_command(*args, **kwargs)
            finally:
                sys.stdout = stdout
            return self

        @property
        def stdout(self):
            return self.io.getvalue()

    return CallCommand() 
開發者ID:GaretJax,項目名稱:django-click,代碼行數:24,代碼來源:conftest.py

示例11: test_examine_log

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import stdout [as 別名]
def test_examine_log(self):
        announce('test_examine_log')
        report = True
        logfile_name = self.env.props.props["log_fname"].val
        list_for_reference = deque(maxlen=16)

        with open(logfile_name, 'rt') as log:
            for line in log:
                list_for_reference.append(line)
        orig_out = sys.stdout
        sys.stdout = open("checklog.txt", "w")
        self.env.disp_log()
        sys.stdout.close()
        sys.stdout = orig_out
        f = open("checklog.txt", "r")
        first_line = f.readline().strip()
        first_line = first_line.split(" ")
        if logfile_name != first_line[-1]:
            report = False
        if report:
            for i, line in enumerate(f):
                if list_for_reference[i] != line:
                    report = False
                    break
        f.close()

        os.remove("checklog.txt")

        self.assertEqual(report, True) 
開發者ID:gcallah,項目名稱:indras_net,代碼行數:31,代碼來源:test_party.py

示例12: main

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import stdout [as 別名]
def main():
    """
    Main application loop.
    """

    env = os.environ

    try:
        host = env['SYSLOG_SERVER']
        port = int(env['SYSLOG_PORT'])
        socktype = socket.SOCK_DGRAM if env['SYSLOG_PROTO'] == 'udp' \
            else socket.SOCK_STREAM
    except KeyError:
        sys.exit("SYSLOG_SERVER, SYSLOG_PORT and SYSLOG_PROTO are required.")

    handler = SysLogHandler(
        address=(host, port),
        socktype=socktype,
    )
    handler.setFormatter(PalletFormatter())

    for event_headers, event_data in supervisor_events(sys.stdin, sys.stdout):
        event = logging.LogRecord(
            name=event_headers['processname'],
            level=logging.INFO,
            pathname=None,
            lineno=0,
            msg=event_data,
            args=(),
            exc_info=None,
        )
        event.process = int(event_headers['pid'])
        handler.handle(event) 
開發者ID:infoxchange,項目名稱:supervisor-logging,代碼行數:35,代碼來源:__init__.py

示例13: test_display_props

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import stdout [as 別名]
def test_display_props(self):
        announce('test_display_props')
        report = True
        orig_out = sys.stdout
        sys.stdout = open("checkprops.txt", "w")
        self.env.disp_props()
        sys.stdout.close()
        sys.stdout = orig_out
        f = open("checkprops.txt", "r")
        title = f.readline()
        title_list = title.split(" for ")
        if self.env.model_nm != title_list[1].strip():
            report = False
        dic_for_check = {}
        if report is True:
            for line in f:
                if line != "\n":
                    line_list = line.split(": ")
                    line_list[0] = line_list[0].strip()
                    line_list[1] = line_list[1].strip()
                    dic_for_check[line_list[0]] = line_list[1]
            for key in self.env.props.props:
                if str(self.env.props.props[key]) != dic_for_check[key]:
                    report = False
        f.close()
        os.remove("checkprops.txt")
        self.assertEqual(report, True) 
開發者ID:gcallah,項目名稱:indras_net,代碼行數:29,代碼來源:test_basic.py

示例14: test_examine_log

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import stdout [as 別名]
def test_examine_log(self):
        announce('test_examine_log')
        report = True
        logfile_name = self.env.props.props["model"].val + ".log"
        list_for_reference = deque(maxlen=16)

        with open(logfile_name, 'rt') as log:
            for line in log:
                list_for_reference.append(line)
        orig_out = sys.stdout
        sys.stdout = open("checklog.txt", "w")
        self.env.disp_log()
        sys.stdout.close()
        sys.stdout = orig_out
        f = open("checklog.txt", "r")
        first_line = f.readline().strip()
        first_line = first_line.split(" ")
        if logfile_name != first_line[-1]:
            report = False
        if report:
            for i, line in enumerate(f):
                if list_for_reference[i] != line:
                    report = False
                    break
        f.close()

        os.remove("checklog.txt")

        self.assertEqual(report, True) 
開發者ID:gcallah,項目名稱:indras_net,代碼行數:31,代碼來源:test_basic.py

示例15: test_display_props

# 需要導入模塊: import sys [as 別名]
# 或者: from sys import stdout [as 別名]
def test_display_props(self):
        announce('test_display_props')
        report = True
        orig_out = sys.stdout
        sys.stdout = open("checkprops.txt", "w")
        self.env.disp_props()
        sys.stdout.close()
        sys.stdout = orig_out
        f = open("checkprops.txt", "r")
        title = f.readline()
        title_list = title.split(" for ")
        if self.env.model_nm != title_list[1].strip():
            report = False
        dic_for_check = {}
        if report is True:
            for line in f:
                if line != "\n":
                    line_list = line.split(": ")
                    line_list[0] = line_list[0].strip()
                    line_list[1] = line_list[1].strip()
                    dic_for_check[line_list[0]] = line_list[1]

            for key in self.env.props.props:
                if str(self.env.props.props[key]) != dic_for_check[key]:
                    report = False
        f.close()
        os.remove("checkprops.txt")
        self.assertEqual(report, True) 
開發者ID:gcallah,項目名稱:indras_net,代碼行數:30,代碼來源:test_coop.py


注:本文中的sys.stdout方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。