While editing the documentation of the builtin open function, I noticed that
the newlines attributes can take on three different value types: None,
strings or tuples of strings. It seems to me it would be better if was
always a set containing the newline values seen so far. There's no testing
necessary if you need to do something with the newlines you've seen, you
just loop over them:
for nl in f.newlines:
print("%r" % nl)
With the current mixed types metaphor you have to do something like this:
if f.newlines is not None:
if type(f.newlines) is tuple:
for nl in f.newlines:
print("%r" % nl)
else:
print("%r" % f.newlines)
This, of course, assumes the file has been opened in text mode. If you have
a binary mode file you also have to call hasattr(f, "newlines"). Presumably
in most cases you'll know the file's mode without needing to check, but
maybe binary files should also have a newlines attribute which is always the
empty set.
Skip
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com