Skip to content
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

feat: Add .remove method to deck class (#681) #682

Merged
merged 7 commits into from
Feb 3, 2025
1 change: 1 addition & 0 deletions doc/changelog/682.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: Add .remove method to deck class (#681)
18 changes: 18 additions & 0 deletions src/ansys/dyna/core/lib/deck.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,24 @@ def append(self, keyword: Union[KeywordBase, str], check=False) -> None:
else:
self._keywords.append(keyword)

def remove(self, index: int | list[int]) -> None:
"""Remove a keyword from the collection by index.

Parameters
----------
index : int or list of int, mandatory
"""
try:
if isinstance(index, int):
del self._keywords[index]
elif isinstance(index, list):
for i in sorted(index, reverse=True):
del self._keywords[i]
else:
raise TypeError("Input must be an integer or a list of integers.")
except IndexError:
raise IndexError(f"One or more indices {index} are out of range for the keywords list.")

def _formatstring(self, string, check=False):
"""Format a string to be appended to the deck."""
linelist = string.split("\n")
Expand Down
Loading