Macaulay2 » Documentation
Packages » Python » PythonObject » PythonObject _ Thing = Thing
next | previous | forward | backward | up | index | toc

PythonObject _ Thing = Thing -- set elements of mutable python sequences

Description

You may set elements of mutable python sequences using _. This is equivalent to square brackets ([]) in Python. For example, this works for lists.

i1 : x = toPython {1, 2, 3, 4}

o1 = [1, 2, 3, 4]

o1 : PythonObject of class list
i2 : x_0 = 5

o2 = 5
i3 : x

o3 = [5, 2, 3, 4]

o3 : PythonObject of class list

It also works for dictionaries.

i4 : x = toPython hashTable {"spam" => 1, "eggs" => 2}

o4 = {'spam': 1, 'eggs': 2}

o4 : PythonObject of class dict
i5 : x_"ham" = 3

o5 = 3
i6 : x

o6 = {'spam': 1, 'eggs': 2, 'ham': 3}

o6 : PythonObject of class dict

Ways to use this method:


The source of this document is in Python/doc/list.m2:55:0.