Macaulay2 » Documentation
Packages » Python :: PythonObject
next | previous | forward | backward | up | index | toc

PythonObject -- a python object

Description

This type corresponds to all objects of the PyObject type in the Python C API, and in particular all of the types that users are familiar with from the Python language itself.

You can perform basic arithmetic on python objects.

i1 : x = pythonValue "5"

o1 = 5

o1 : PythonObject of class int
i2 : y = pythonValue "2"

o2 = 2

o2 : PythonObject of class int
i3 : x + y

o3 = 7

o3 : PythonObject of class int
i4 : x - y

o4 = 3

o4 : PythonObject of class int
i5 : x * y

o5 = 10

o5 : PythonObject of class int
i6 : x / y

o6 = 2.5

o6 : PythonObject of class float

You can also compare them.

i7 : x > y

o7 = true
i8 : x == y

o8 = false

You can also perform operations on python objects and Macaulay2 things. The results will be returned as python objects.

i9 : x + 2

o9 = 7

o9 : PythonObject of class int

Note that many keywords in Macaulay2 are mapped to a certain dunder method in Python. In particular,

Methods that use a python object :

For the programmer

The object PythonObject is a type, with ancestor class Thing.