>You can argue that reading csv data from/writing csv data to a file on >Windows if the file isn't opened in binary mode is an error. Perhaps we >should enforce that in situations where it matters. Would this be a start? > > terminators = {"darwin": "\r", > "win32": "\r\n"} > > if (dialect.lineterminator != terminators.get(sys.platform, "\n") and > "b" not in getattr(f, "mode", "b")): > raise IOError, ("%s not opened in binary mode" % > getattr(f, "name", "???")) > >The elements of the postulated terminators dictionary may already exist >somewhere within the sys or os modules (if not, perhaps they should be >added). The idea of the check is to enforce binary mode on those objects >that support a mode if the desired line terminator doesn't match the >platform's line terminator.
Where that falls down, I think, is where you want to read an alien file - in fact, under unix, most of the CSV files I read use \r\n for end-of-line. Also, I *really* don't like the idea of looking for a mode attribute on the supplied iterator - it feels like a layering violation. We've advertised the fact that it's an iterator, so we shouldn't be using anything but the iterator protocol. -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/ _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com