Macaulay2 » Documentation
Packages » Python » PythonObject » value(PythonObject)
next | previous | forward | backward | up | index | toc

value(PythonObject) -- convert python objects to Macaulay2 things

Description

This function attempts to convert x to its corresponding Macaulay2 equivalent.

i1 : value pythonValue "[1, 3.14159, 'foo', (1,2,3), {'foo':'bar'}]"

o1 = {1, 3.14159, foo, (1, 2, 3), HashTable{"foo" => bar}}

o1 : List
i2 : class \ oo

o2 = {ZZ, RR, String, Sequence, HashTable}

o2 : List

Since the type of x is not initially known, a sequence of hooks are used to determine its type and then convert it.

i3 : hooks value

o3 = {0 => (value, PythonObject, Strategy => unknown -> PythonObject)                    }
     {1 => (value, PythonObject, Strategy => collections.abc.Callable -> FunctionClosure)}
     {2 => (value, PythonObject, Strategy => collections.abc.Mapping -> HashTable)       }
     {3 => (value, PythonObject, Strategy => collections.abc.Set -> Set)                 }
     {4 => (value, PythonObject, Strategy => collections.abc.Sequence -> Sequence)       }
     {5 => (value, PythonObject, Strategy => collections.abc.MutableSequence -> List)    }
     {6 => (value, PythonObject, Strategy => str -> String)                              }
     {7 => (value, PythonObject, Strategy => numbers.Complex -> CC)                      }
     {8 => (value, PythonObject, Strategy => numbers.Real -> RR)                         }
     {9 => (value, PythonObject, Strategy => numbers.Integral -> ZZ)                     }
     {10 => (value, PythonObject, Strategy => bool -> Boolean)                           }

o3 : NumberedVerticalList

If no conversion can be done, then x is returned.

Users may add additional hooks using addHook or the convenience function addPyToM2Function.

Ways to use this method:


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