[Python-Dev] Optional separatorargument for file.writelines() and StringIO.writelines() (original) (raw)
Alex Martelli aleaxit at yahoo.com
Wed Feb 25 03:40:56 EST 2004
- Previous message: [Python-Dev] Optional separatorargument for file.writelines() and StringIO.writelines()
- Next message: [Python-Dev] Re: Optional separatorargument for file.writelines() and StringIO.writelines()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 2004 Feb 25, at 12:13, Dmitry Vasiliev wrote:
Raymond Hettinger wrote:
Currently, writelines() does not add trailing line separators.. This is fine when working with readlines() but a PITA in other situations. If we added an optional separator argument, it would be easier to add newlines and we would gain some of the flexibility of str.join() at full C speed. Maybe not a separator but suffix, so newline will be added to last line too?
Good point. And while a separator would be a slight nuisance to express otherwise, a "suffix" isn't -- it seems to me that f.writelines(x+'\n' for x in mylines) is a rather good way of expressing "suffix each line with a \n". I don't think this suffixing operation is so widely more important than other elaborations on items of mylines to make it worth specialcasing into a writelines argument [if anything, f.writelines(str(x) for x in mylines) would be the one elaboration that seems to me to be by far the most frequent -- still not worth specialcasing though, IMHO].
Alex
- Previous message: [Python-Dev] Optional separatorargument for file.writelines() and StringIO.writelines()
- Next message: [Python-Dev] Re: Optional separatorargument for file.writelines() and StringIO.writelines()
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]