Skip to content

Commit

Permalink
files/inp: added __getitem__ methods
Browse files Browse the repository at this point in the history
  • Loading branch information
BitterB0NG0 committed Oct 28, 2024
1 parent ff59fc9 commit 4cc14b7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/pymcnp/files/inp/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,12 @@ def to_arguments(self) -> list:
"""

return [card.to_arguments() for card in self._cards.values()]

def __getitem__(self, index: int) -> Cell:
try:
return self._cards[index]
except KeyError:
raise KeyError

def __contains__(self, item: str) -> Cell:
return item in self._cards
9 changes: 9 additions & 0 deletions src/pymcnp/files/inp/surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,12 @@ def to_cadquery_file(self, filename: str, hasHeader: bool = True) -> None:

with open(filename, 'w') as file:
file.write(self.to_cadquery(hasHeader))

def __getitem__(self, index: int) -> Surface:
try:
return self._cards[index]
except KeyError:
raise KeyError

def __contains__(self, item: str) -> Surface:
return item in self._cards

0 comments on commit 4cc14b7

Please sign in to comment.