create file modes
tarikaltuncu opened this issue · 3 comments
Hi there,
I can't find w+ mode to create a file if it does not exist already. I believe it'd be nice to have it.
Best
yep, not currently possible. though it is fairly simple to add. wanna make a pr for it?
in the mean time you can just open your file and pass it to jsonlines.Writer()
manually. jsonlines.open()
is only for convenience.
@Beginner789 made a pr #47 for this, but i actually don't understand what's the use case here.
@tarikaltuncu wrote in the original report:
find w+ mode to create a file if it does not exist already
but that's not what w+
seems to do; see the docs for open().
a simple w
mode will
open for writing, truncating the file first
and a
will
open for writing, appending to the end of the file if it exists
both w
and a
are already supported by jsonlines.open()
since they are useful patterns for writing data, as is r
for readin. jsonlines
has a Reader
for reading, and a Writer
for writing. the jsonlines.open()
function is just a convenience function to quickly choose one of the two by simply passing a file name and a mode.
the file open modes with a +
all involve both reading and writing from the same file, which doesn't seem to make any sense as a use case for this library.