Suggestion for documentation improvement

Dear python developpers, I ran into the unicode problem of the csv module in the python standard library (2.7.5) and immediately found the solution in the docs. I just used the UTF8Recoder/UnicodeReader/UnicodeWriter proposed in http://docs.python.org/2/library/csv.html#examples. Thank you for that! There is just one little problem with UnicodeWriter, which imho has an easy solution: class UnicodeWriter: "..." def writerow(self, row): self.writer.writerow([s.encode("utf-8") for s in row]) "..." When "s" is not a string (i.e. when "row" contains an element, that is e.g. None or an int, which is ok for csv.writer), I get a "AttributeError: 'NoneType' object has no attribute 'encode'" So I changed this bit of code to def writerow(self, row): self.writer.writerow([unicode(s).encode("utf-8") if s is not None else "" for s in row]) "..." Ok, this is a bit complicated for an educational code sample, but I think there are more people like me, that just use the code samples from the docs. Best regards, Johannes
participants (1)
-
Johannes Ammon