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

getattr -- get an attribute of a python object

Synopsis

Description

This is equivalent to the Python getattr function.

i1 : foo = pythonValue "'Hello, world!'"

o1 = Hello, world!

o1 : PythonObject of class str
i2 : (getattr(foo, "upper"))()

o2 = HELLO, WORLD!

o2 : PythonObject of class str

In Python, "." is generally used as a shortcut for this function, but it is not easily overloadable in Macaulay2. Instead, @@ may be used for this purpose, as its precedence is similar to "." In this case, y need not be a string.

i3 : foo@@lower()

o3 = hello, world!

o3 : PythonObject of class str

Ways to use getattr :

For the programmer

The object getattr is a method function.