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


Python stderr.write方法代碼示例

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


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

示例1: dump

# 需要導入模塊: from sys import stderr [as 別名]
# 或者: from sys.stderr import write [as 別名]
def dump(state):
    if not options.DUMP_PRE_ERROR_STATE:
        return
    stdout.flush()
    stderr.flush()
    stdout.write(
        "\n--- Pre-error state dump: --------------------------------------------\n"
    )
    try:
        state.dump()
    finally:
        stdout.write(
            "----------------------------------------------------------------------\n"
        )
        stderr.write("\n")
        stdout.flush()
        stderr.flush() 
開發者ID:quora,項目名稱:asynq,代碼行數:19,代碼來源:debug.py

示例2: __get_request

# 需要導入模塊: from sys import stderr [as 別名]
# 或者: from sys.stderr import write [as 別名]
def __get_request(self, url, max_try=3):
        stderr.write(url + '\n')
        cnt = 0
        while cnt < max_try:
            try:
                req = requests.get(url, headers=self.headers)
            except:
                cnt += 1
                continue
            if req.status_code != requests.codes.ok:
                break
            return req
        # Should not reach here if everything is ok.
        stderr.write(json.dumps(self.data, ensure_ascii=False, sort_keys=True, indent=4).encode('utf-8', 'replace'))
        stderr.write('Error: %s\n' % url)
        exit(1) 
開發者ID:intfloat,項目名稱:sina-weibo-crawler,代碼行數:18,代碼來源:wcrawler.py

示例3: __parse_weibo

# 需要導入模塊: from sys import stderr [as 別名]
# 或者: from sys.stderr import write [as 別名]
def __parse_weibo(self, soup):
        # return all weibo in a page as a list
        ret = []
        for block in soup.find_all('div', 'c'):
            divs = block.find_all('div')
            if len(divs) == 1:
                text = self.__trim_like(divs[0].get_text())
                ret.append(text)
            elif len(divs) == 2 or len(divs) == 3:
                text = self.__trim_like(divs[0].get_text())
                comment = self.__trim_like(divs[-1].get_text())
                ret.append(text + comment)
            elif len(divs) == 0:
                continue
            else:
                stderr.write('Error: invalid weibo page')
                exit(1)
        return ret 
開發者ID:intfloat,項目名稱:sina-weibo-crawler,代碼行數:20,代碼來源:wcrawler.py

示例4: integer_list_file

# 需要導入模塊: from sys import stderr [as 別名]
# 或者: from sys.stderr import write [as 別名]
def integer_list_file(cls, filename, values, bits = None):
        """
        Write a list of integers to a file.
        If a file of the same name exists, it's contents are replaced.

        See L{HexInput.integer_list_file} for a description of the file format.

        @type  filename: str
        @param filename: Name of the file to write.

        @type  values: list( int )
        @param values: List of integers to write to the file.

        @type  bits: int
        @param bits:
            (Optional) Number of bits of the target architecture.
            The default is platform dependent. See: L{HexOutput.integer_size}
        """
        fd = open(filename, 'w')
        for integer in values:
            print >> fd, cls.integer(integer, bits)
        fd.close() 
開發者ID:fabioz,項目名稱:PyDev.Debugger,代碼行數:24,代碼來源:textio.py

示例5: string_list_file

# 需要導入模塊: from sys import stderr [as 別名]
# 或者: from sys.stderr import write [as 別名]
def string_list_file(cls, filename, values):
        """
        Write a list of strings to a file.
        If a file of the same name exists, it's contents are replaced.

        See L{HexInput.string_list_file} for a description of the file format.

        @type  filename: str
        @param filename: Name of the file to write.

        @type  values: list( int )
        @param values: List of strings to write to the file.
        """
        fd = open(filename, 'w')
        for string in values:
            print >> fd, string
        fd.close() 
開發者ID:fabioz,項目名稱:PyDev.Debugger,代碼行數:19,代碼來源:textio.py

示例6: __logfile_error

# 需要導入模塊: from sys import stderr [as 別名]
# 或者: from sys.stderr import write [as 別名]
def __logfile_error(self, e):
        """
        Shows an error message to standard error
        if the log file can't be written to.

        Used internally.

        @type  e: Exception
        @param e: Exception raised when trying to write to the log file.
        """
        from sys import stderr
        msg = "Warning, error writing log file %s: %s\n"
        msg = msg % (self.logfile, str(e))
        stderr.write(DebugLog.log_text(msg))
        self.logfile = None
        self.fd      = None 
開發者ID:fabioz,項目名稱:PyDev.Debugger,代碼行數:18,代碼來源:textio.py

示例7: getnode

# 需要導入模塊: from sys import stderr [as 別名]
# 或者: from sys.stderr import write [as 別名]
def getnode(self):

        if self.xnode == None:
            x_node_ptr = unpacktype(self.smem, self.template['v_data'], INT)

            if self.tag == None:
                self.tag = unpacktype(self.smem, self.template['v_tag'], SHT)

            if self.tag == 16:  # VT_HFS
                self.xnode = Cnode(x_node_ptr)

            elif self.tag == 18:  # VT_DEVFS
                self.xnode = Devnode(x_node_ptr)

            else:
                if self.tag < len(Vnode.VNODE_TAG):
                    s_tag = Vnode.VNODE_TAG[self.tag]
                else:
                    s_tag = str(self.tag)
                stderr.write("WARNING Vnode.getnode(): unsupported FS tag %s, returning %d.\n" % (s_tag, ECODE['node']))
                return ECODE['node']

        return self.xnode.getnode() 
開發者ID:n0fate,項目名稱:volafox,代碼行數:25,代碼來源:lsof.py

示例8: getdev

# 需要導入模塊: from sys import stderr [as 別名]
# 或者: from sys.stderr import write [as 別名]
def getdev(self):

        if self.tag == None:
            self.tag = unpacktype(self.smem, self.template['v_tag'], SHT)

        if self.tag == 18:  # CHR
            vu_specinfo = unpacktype(self.smem, self.template['v_un'], INT)

            # this pointer is invalid for /dev (special case DIR using VT_DEVFS)
            if not (vu_specinfo == 0) and Struct.mem.is_valid_address(vu_specinfo):
                specinfo = Specinfo(vu_specinfo)
                return specinfo.getdev()

        # default return for REG/DIR/LINK
        if self.mount == None:
            mount_ptr = unpacktype(self.smem, self.template['v_mount'], INT)

            if mount_ptr == 0 or not (Struct.mem.is_valid_address(mount_ptr)):
                stderr.write("WARNING Vnode.getdev(): v_mount pointer invalid, returning %d.\n" % ECODE['device'])
                return ECODE['device']

            self.mount = Mount(mount_ptr)

        return self.mount.getdev() 
開發者ID:n0fate,項目名稱:volafox,代碼行數:26,代碼來源:lsof.py

示例9: SaveToFile

# 需要導入模塊: from sys import stderr [as 別名]
# 或者: from sys.stderr import write [as 別名]
def SaveToFile(self, filename, canvas):
        if hasattr(getattr(filename, "write",None),'__call__'):
            myfile = 0
            f = filename
            filename = makeFileName(getattr(filename,'name',''))
        else :
            myfile = 1
            filename = makeFileName(filename)
            f = open(filename, "wb")
        data = self.GetPDFData(canvas)
        if isUnicode(data):
            data = data.encode('latin1')
        f.write(data)
        if myfile:
            f.close()
            import os
            if os.name=='mac':
                from reportlab.lib.utils import markfilename
                markfilename(filename) # do platform specific file junk
        if getattr(canvas,'_verbosity',None): print('saved %s' % (filename,)) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:22,代碼來源:pdfdoc.py

示例10: evaluate

# 需要導入模塊: from sys import stderr [as 別名]
# 或者: from sys.stderr import write [as 別名]
def evaluate(operations, DEBUG=False):
    from subprocess import Popen, PIPE

    if DEBUG:
        print
        print operations
        print
    inp = send(operations)
    if DEBUG:
        print inp
        print
    with open('vhe.in', 'w') as f:
        f.write(inp)
    output, error = Popen(['./vhe'], stdin=PIPE, stdout=PIPE, shell=True).communicate('')
    if DEBUG:
        print output
        print
    
    if error:
        from sys import stderr
        stderr.write(error + '\n')
        stderr.flush()

    return recv(output) 
開發者ID:jamespayor,項目名稱:vector-homomorphic-encryption,代碼行數:26,代碼來源:hevector.py

示例11: zipdir

# 需要導入模塊: from sys import stderr [as 別名]
# 或者: from sys.stderr import write [as 別名]
def zipdir(archivename, basedir, ignoredirs=None):
    '''Zip directory, from J.F. Sebastian http://stackoverflow.com/'''
    assert os.path.isdir(basedir)
    if not ignoredirs:
        ignoredirs = []
    with closing(ZipFile(archivename, "w", ZIP_DEFLATED)) as z:
        for root, dirs, files in os.walk(basedir):
            for folder in copy.copy(dirs):
                abspath = os.path.abspath(os.path.join(root, folder))
                if abspath in ignoredirs:
                    dirs.remove(folder)

            # NOTE: ignore empty directories
            for fn in files:
                if fn[-4:]!='.zip':
                    absfn = os.path.join(root, fn)
                    zfn = absfn[len(basedir)+len(os.sep):]  # XXX: relative path
                    z.write(absfn, zfn)
                    
# ================ Inventory input data and create data structure ================= 
開發者ID:jamesrobertlloyd,項目名稱:automl-phase-2,代碼行數:22,代碼來源:data_io.py

示例12: printexpr

# 需要導入模塊: from sys import stderr [as 別名]
# 或者: from sys.stderr import write [as 別名]
def printexpr(expr_string):
    """ printexpr(expr) - 
        print the value of the expression, along with linenumber and filename.
    """

    stack = extract_stack ( )[-2:][0]
    actualCall = stack[3]
    left = string.find ( actualCall, '(' )
    right = string.rfind ( actualCall, ')' )
    caller_globals,caller_locals = _caller_symbols()
    expr = eval(expr_string,caller_globals,caller_locals)
    varType = type( expr )
    stderr.write("%s:%d>  %s == %s  (%s)\n" % (
        stack[0], stack[1],
        string.strip( actualCall[left+1:right] )[1:-1],
        repr(expr), str(varType)[7:-2])) 
開發者ID:ActiveState,項目名稱:code,代碼行數:18,代碼來源:recipe-52278.py

示例13: tempfile

# 需要導入模塊: from sys import stderr [as 別名]
# 或者: from sys.stderr import write [as 別名]
def tempfile(self,calcMD5=False,calcSHA1=False,calcSHA256=False):
        """Return the contents of imagefile in a named temporary file. If
        calcMD5, calcSHA1, or calcSHA256 are set TRUE, then the object
        returned has a hashlib object as self.md5 or self.sha1 with the
        requested hash."""
        import tempfile
        tf = tempfile.NamedTemporaryFile()
        if calcMD5: tf.md5 = hashlib.md5()
        if calcSHA1: tf.sha1 = hashlib.sha1()
        if calcSHA256: tf.sha256 = hashlib.sha256()
        for run in self.byte_runs():
            self.imagefile.seek(run.img_offset)
            count = run.len
            while count>0:
                xfer_len = min(count,1024*1024)        # transfer up to a megabyte at a time
                buf = self.imagefile.read(xfer_len)
                if len(buf)==0: break
                tf.write(buf)
                if calcMD5: tf.md5.update(buf)
                if calcSHA1: tf.sha1.update(buf)
                if calcSHA256: tf.sha256.update(buf)
                count -= xfer_len
        tf.flush()
        return tf 
開發者ID:kieranjol,項目名稱:IFIscripts,代碼行數:26,代碼來源:dfxml.py

示例14: __call__

# 需要導入模塊: from sys import stderr [as 別名]
# 或者: from sys.stderr import write [as 別名]
def __call__(self):
        with self._lock:
            if self._nbytes >= 0:
                self._data[self._hpath] = self._nbytes
            else:
                stderr.write('%s\n' % (sum(self._data.values()), )) 
開發者ID:apache,項目名稱:incubator-spot,代碼行數:8,代碼來源:hdfs_client.py

示例15: put_file_csv

# 需要導入模塊: from sys import stderr [as 別名]
# 或者: from sys.stderr import write [as 別名]
def put_file_csv(hdfs_file_content,hdfs_path,hdfs_file_name,append_file=False,overwrite_file=False, client=None):
    if not client:
        client = get_client()

    try:
        hdfs_full_name = "{0}/{1}".format(hdfs_path,hdfs_file_name)
        with client.write(hdfs_full_name,append=append_file,overwrite=overwrite_file) as writer:
            for item in hdfs_file_content:
                data = ','.join(str(d) for d in item)
                writer.write("{0}\n".format(data))
        return True

    except HdfsError:
        return False 
開發者ID:apache,項目名稱:incubator-spot,代碼行數:16,代碼來源:hdfs_client.py


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