The suggestion Skip is indeed very useful, however it does not work when some of the item is not string, here is another try: class UnicodeReader: def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds): self.reader = csv.reader(f, dialect=dialect, **kwds) self.encoding = encoding def next(self): row = self.reader.next() t = [] for s in row: try: t.append(unicode(s,self.encoding)) except: t.append(s) return t # [unicode(s, self.encoding) for s in row] This will not work with non string type def __iter__(self): return self class UnicodeWriter: def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds): self.writer = csv.writer(f, dialect=dialect, **kwds) self.encoding = encoding def writerow(self, row): t = [] for s in row: try: t.append(unicode(s,"utf-8")) except: t.append(s) self.writer.writerow(t) #self.writer.writerow([s.encode("utf-8") for s in row]) #! This is not working with non-string objects. def writerows(self, rows): for row in rows: self.writerow(row) -- Sin Hang Kin.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4