next | previous | forward | backward | up | top | index | toc | Macaulay2 website
Python :: toPython

toPython -- convert Macaulay2 things to Python objects

Synopsis

Description

Attempt to convert a Macaulay2 thing to a Python object.

i1 : toPython 2

o1 = 2

o1 : PythonObject of class int
i2 : toPython (1/2)

o2 = 0.5

o2 : PythonObject of class float
i3 : toPython pi

o3 = 3.141592653589793

o3 : PythonObject of class float
i4 : toPython ii

o4 = 1j

o4 : PythonObject of class complex
i5 : toPython "foo"

o5 = foo

o5 : PythonObject of class str
i6 : toPython {1, 2, 3, 4}

o6 = [1, 2, 3, 4]

o6 : PythonObject of class list
i7 : toPython (1, 2, 3, 4)

o7 = (1, 2, 3, 4)

o7 : PythonObject of class tuple
i8 : toPython hashTable {"foo" => "bar"}

o8 = {'foo': 'bar'}

o8 : PythonObject of class dict
i9 : toPython set {1, 2, 3, 4}

o9 = {1, 2, 3, 4}

o9 : PythonObject of class set
i10 : toPython true

o10 = True

o10 : PythonObject of class bool
i11 : toPython null

o11 = None

o11 : PythonObject of class NoneType

Ways to use toPython :

For the programmer

The object toPython is a method function with a single argument.