Skip to content

Commit

Permalink
Merge pull request #5 from gerlero/dictionary
Browse files Browse the repository at this point in the history
Update dictionary assignment logic
  • Loading branch information
gerlero authored Mar 19, 2024
2 parents a77577a + 5fe0acd commit f770544
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions foamlib/_dictionaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,13 @@ def __setitem__(self, key: str, value: Any) -> None:

value = self._str(value, assume_field=assume_field)

self._cmd(["-set", "_foamlib_value_"], key=key)

contents = self._file.path.read_text()
contents = contents.replace("_foamlib_value_", value, 1)
self._file.path.write_text(contents)
if len(value) < 1000:
self._cmd(["-set", value], key=key)
else:
self._cmd(["-set", "_foamlib_value_"], key=key)
contents = self._file.path.read_text()
contents = contents.replace("_foamlib_value_", value, 1)
self._file.path.write_text(contents)

def __delitem__(self, key: str) -> None:
if key not in self:
Expand Down

0 comments on commit f770544

Please sign in to comment.