我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用io.StringIO.write()。
def __init__(self, out=True, err=True, in_=True, mixed=False, now=True): self._oldout = sys.stdout self._olderr = sys.stderr self._oldin = sys.stdin if out and not hasattr(out, 'file'): out = TextIO() self.out = out if err: if mixed: err = out elif not hasattr(err, 'write'): err = TextIO() self.err = err self.in_ = in_ if now: self.startall()
def __init__(self, initial_value='', newline='\n', callback_write=None): """ Overloads the StringIO.__init__() makes it possible to hook a callback for write operations. """ self.callback_write = callback_write super(StringIOCBWrite, self).__init__(initial_value, newline)
def write(self, s): """ Calls the StringIO.write() method then the callback_write with given string parameter. """ # io.StringIO expects unicode s_unicode = s.decode('utf-8') super(StringIOCBWrite, self).write(s_unicode) if self.callback_write is not None: self.callback_write(s_unicode)
def write(self, data): if not isinstance(data, unicode): data = unicode(data, getattr(self, '_encoding', 'UTF-8'), 'replace') StringIO.write(self, data)
def write(self, data): if isinstance(data, unicode): raise TypeError("not a byte value: %r" %(data,)) StringIO.write(self, data)
def writeorg(self, data): """ write a string to the original file descriptor """ tempfp = tempfile.TemporaryFile() try: os.dup2(self._savefd, tempfp.fileno()) tempfp.write(data) finally: tempfp.close()
def write(self, obj): if isinstance(obj, unicode): obj = obj.encode(self.encoding) elif isinstance(obj, str): pass else: obj = str(obj) self._stream.write(obj)
def writelines(self, linelist): data = ''.join(linelist) self.write(data)
def write(self, data): if not isinstance(data, unicode): data = data.decode('utf-8') StringIO.write(self, data) ############################################################################### # The following strings are used when we have several pictures: we use # an html div tag that our CSS uses to turn the lists into horizontal # lists.
def write(self, data): self.file1.write(data) self.file2.write(data)
def _save(self): in_ = self._options['in_'] out = self._options['out'] err = self._options['err'] mixed = self._options['mixed'] patchsys = self._options['patchsys'] if in_: try: self.in_ = FDCapture(0, tmpfile=None, now=False, patchsys=patchsys) except OSError: pass if out: tmpfile = None if hasattr(out, 'write'): tmpfile = out try: self.out = FDCapture(1, tmpfile=tmpfile, now=False, patchsys=patchsys) self._options['out'] = self.out.tmpfile except OSError: pass if err: if out and mixed: tmpfile = self.out.tmpfile elif hasattr(err, 'write'): tmpfile = err else: tmpfile = None try: self.err = FDCapture(2, tmpfile=tmpfile, now=False, patchsys=patchsys) self._options['err'] = self.err.tmpfile except OSError: pass
def write(self, data): if isinstance(data, bytes): data = data.encode() StringIO.write(self, data)
def write(self, s): StringIO.write(self, s) self.func(self.getvalue()) self.seek(0) self.truncate(0)