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

setattr -- set an attribute of a python object

Synopsis

Description

This is equivalent to the Python setattr function. Note that e is converted to a Python object using toPython.

i1 : math = import "math"

o1 = <module 'math' (built-in)>

o1 : PythonObject of class module
i2 : setattr(math, "pi", 22/7)
i3 : math@@pi

o3 = 3.142857142857143

o3 : PythonObject of class float

As with getattr, when using the shortcut @@, y need not be a string.

i4 : math@@e = 19/7
i5 : math@@e

o5 = 2.7142857142857144

o5 : PythonObject of class float

Ways to use setattr :

For the programmer

The object setattr is a method function.