我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用encodings.utf_8()。
def __init__(self, stream, fieldnames, encoding='utf-8', **kwds): """Initialzer. Args: stream: Stream to write to. fieldnames: Fieldnames to pass to the DictWriter. encoding: Desired encoding. kwds: Additional arguments to pass to the DictWriter. """ writer = codecs.getwriter(encoding) if (writer is encodings.utf_8.StreamWriter or writer is encodings.ascii.StreamWriter or writer is encodings.latin_1.StreamWriter or writer is encodings.cp1252.StreamWriter): self.no_recoding = True self.encoder = codecs.getencoder(encoding) self.writer = csv.DictWriter(stream, fieldnames, **kwds) else: self.no_recoding = False self.encoder = codecs.getencoder('utf-8') self.queue = cStringIO.StringIO() self.writer = csv.DictWriter(self.queue, fieldnames, **kwds) self.stream = writer(stream)
def lookup(encoding): """lookup(encoding) -> CodecInfo Looks up a codec tuple in the Python codec registry and returns a CodecInfo object.""" if encoding in ('utf-8', 'utf_8'): from javascript import console console.log('encoding', encoding) import encodings.utf_8 return encodings.utf_8.getregentry() LookupError(encoding)