-
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
Allow to remove items while patching #77
Comments
I'm guessing your use case is that you want to remove an entry while keeping the whitespace/comments in place, is that right? If so then I agree, this does not seem to be possible at the moment. Namelists have some concept of null values, for example this is a valid namelist:
which leaves
I've been adding these special tags to support other things like complex variables and starting index, so it ought not be a problem. |
I had a few mistakes in my last post, which I've edited, sorry about that. I think that I'd probably prefer the special tag approach, since it would be more usable with the command line tool and more consistent with other convertible formats, e.g. JSON. Would that work for you? |
I agree, yes, it makes more sense to use |
I have a workaround for this. I add '_delete' to my patch and iterate through the namelist deleting members contained in _delete and then removing '_delete' from the patch. Then I can patch like usual: patch = {
'time_control': {
'_delete': ['debug_level']
'field_to_set': 0
}
}
keys = [(group, member) for group in patch for member in patch[group]]
for group, member in keys:
if member == '_delete':
for member_to_delete in patch[group][member]:
del namelist[group][member_to_delete]
del patch[group][member]
namelist.patch(patch) This is a hack, but maybe it could it be a start for a proper feature addition? |
The long term plan (now very very long term) was to integrate this feature in to the new parser, but that's been in hold for a very long time. So I'd say that if you have something that works then it'd be most welcome :). |
I have the use case where I'd like to remove an existing key by somehome indicating this in the patch dictionary. I tried
"key": None
but that doesn't have any effect. How about introducing a special object that can be used for this purpose, like"key": f90nml.Delete
?The text was updated successfully, but these errors were encountered: