Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 312c3c8

Browse files
author
Matthias Koeppe
committed
PolymakeElement.__setitem__: New
1 parent a1e1a8f commit 312c3c8

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/sage/interfaces/polymake.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,27 @@ def __getitem__(self, key):
13801380
return P(self._name + "{" + key + "}")
13811381
raise NotImplementedError("Cannot get items from Perl type {}".format(T))
13821382

1383+
def __setitem__(self, key, value):
1384+
"""
1385+
Set an element of an array.
1386+
1387+
EXAMPLES::
1388+
1389+
sage: V = polymake.new_object('Vector', [1,0,0]) # optional - polymake
1390+
sage: V # optional - polymake
1391+
1 0 0
1392+
sage: V[1] = 42
1393+
sage: V
1394+
1 42 0
1395+
1396+
"""
1397+
P = self._check_valid()
1398+
_, T = self.typeof()
1399+
if T == 'ARRAY':
1400+
P.eval('{}->[{}] = {};'.format(self._name, key, P(value)._name))
1401+
else:
1402+
raise NotImplementedError("Cannot set items of Perl type {}".format(T))
1403+
13831404
def __iter__(self):
13841405
"""
13851406
Return an iterator for ``self``.

0 commit comments

Comments
 (0)