-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File APIs #25
Comments
Yes, using paths is a bit dumdum, a bad decision that I now feel a bit stuck with. I've mostly been waiting for someone to object before changing this. You win the prize! I'm willing to break the API (techincally, it's not a 1.0 yet) but I think the approach of As for all the I'll get started on this. |
Ah, so fast! I began to take a stab at it myself shortly after posting (using a slightly different approach which looked something like this, which is crap by the way and I've already found a couple bugs), but certainly you know the code better, so I'm glad you're already on top of this! :D |
That patch looks OK to me, do you want to send it as a pull request? I can modify it if there's any problems with it. |
I just gave this patch a try, I think the I'd be interested to hear how you go with it. edit Sorry, false alarm, I didn't have the |
I see some of the ideas have already made it in there. I could submit a P.S. in that link there were actually two patches, where the second one is On Tue, Mar 1, 2016 at 5:53 AM, Marshall Ward notifications@github.com
|
I'll close this now that v0.18 has file APIs |
Did you still want to add string support ( |
Yeah, I still think they're a good idea for ergonomics. I didn't push too hard for them since unlike the file apis, these can be implemented as wrapper functions. I will open a separate issue |
Feature request:
Currently
f90nml
only accepts filenames for its input and output files. This generally restricts the usage off90nml
in comparison to other serialization libraries in Python, which usually have methods for working with arbitrary file-like objects and string data (E.g.json
andpickle
havedump/load
for file-like objects anddumps/loads
for strings.xml.etree
hasparse
which accepts both filenames and file-like objects, andfromstring
for strings.)For some examples of how these APIs are useful: Currently, it is not possible to parse an NML file directly from
sys.stdin
or to write one tosys.stdout
, because these are already-open files with no path. It is similarly difficult to apply multiple patches in a row (whereas with a string api it would just befor patch in patches: s = f90nml.patchstr(s, patch)
). Currently I work around these limitations usingNamedTemporaryFile
, which has a fair number of quirks about it and is something I generally consider to be a last resort.Some thoughts:
f.read()
,f.write()
), or to write string-based wrappers around file functions (usingStringIO
).patch
which takes two files, I feel that the API would be cleanest ifread
,write
, andpatch
were modified to detect if their arguments are paths or a file-like object (e.g. withhasattr(infile, 'read')
). This way a user could mix and match, e.g. read from a file object and write to a path. In any case, though, strings will require their own functions (e.g.readstr(s)
,writestr(nml)
, andpatchstr(s, patch)
or however you want to name them).patchstr
should return just a string, or if it should return(string, nml)
(sincepatch
returns an NML).close
. I bring this up because there are several calls toclose()
currently embedded inside the parsing functions.The text was updated successfully, but these errors were encountered: