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

Python -- interface to Python

Description

This package provides a basic interface to run Python code within Macaulay2 and to convert back and forth between Python and Macaulay2 objects.

i1 : toPython {1, 2/3, "foo", (1, 2, 3), hashTable {"foo" => "bar"}}

o1 = [1, 0.6666666666666666, 'foo', (1, 2, 3), {'foo': 'bar'}]

o1 : PythonObject of class list
i2 : value rs "[1, 2/3, 'foo', (1, 2, 3), {'foo' : 'bar'}]"

o2 = {1, .666667, foo, (1, 2, 3), HashTable{foo => bar}}

o2 : List
i3 : math = import "math"

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

o3 : PythonObject of class module
i4 : math@@sqrt 2

o4 = 1.4142135623730951

o4 : PythonObject of class float

Authors

Version

This documentation describes version 0.2 of Python.

Source code

The source code from which this documentation is derived is in the file Python.m2. The auxiliary files accompanying it are in the directory Python/.

Exports

  • Types
  • Functions and commands
    • addPyToM2Function -- convenience function for adding value hooks
    • context (missing documentation)
    • getattr -- get an attribute of a python object
    • getitem -- get elements of python sequences
    • hasattr -- whether a python object has an attribute
    • import -- import a Python module
    • iter -- get iterator of iterable python object
    • iterableToList -- convert an iterable python object to a Macaulay2 list
    • next -- retrieve the next item from a python iterator
    • objectType -- type of a python object
    • pythonHelp (missing documentation)
    • rs -- execute Python source code from a string
    • "runPythonString" -- see rs -- execute Python source code from a string
    • runSimpleString -- execute Python source code from a string in __main__
    • setattr -- set an attribute of a python object
    • setitem -- set elements of mutable python sequences
    • toFunction -- convert callable python objects to Macaulay2 functions
    • toPython -- convert Macaulay2 things to Python objects
  • Methods
    • "addPyToM2Function(List,Function,String)" -- see addPyToM2Function -- convenience function for adding value hooks
    • "addPyToM2Function(String,Function,String)" -- see addPyToM2Function -- convenience function for adding value hooks
    • "getattr(PythonObject,String)" -- see getattr -- get an attribute of a python object
    • "PythonObject @@ Thing" -- see getattr -- get an attribute of a python object
    • "getitem(PythonObject,Thing)" -- see getitem -- get elements of python sequences
    • "PythonObject _ Thing" -- see getitem -- get elements of python sequences
    • "hasattr(PythonObject,String)" -- see hasattr -- whether a python object has an attribute
    • "import(String)" -- see import -- import a Python module
    • "iter(PythonObject)" -- see iter -- get iterator of iterable python object
    • "iterableToList(PythonObject)" -- see iterableToList -- convert an iterable python object to a Macaulay2 list
    • length(PythonObject) -- returns the length of a python object
    • "next(PythonObject)" -- see next -- retrieve the next item from a python iterator
    • "PythonObject % PythonObject" -- see PythonObject -- a python object
    • "PythonObject % Thing" -- see PythonObject -- a python object
    • "PythonObject & PythonObject" -- see PythonObject -- a python object
    • "PythonObject & Thing" -- see PythonObject -- a python object
    • "PythonObject * PythonObject" -- see PythonObject -- a python object
    • "PythonObject * Thing" -- see PythonObject -- a python object
    • "PythonObject + PythonObject" -- see PythonObject -- a python object
    • "PythonObject + Thing" -- see PythonObject -- a python object
    • "PythonObject - PythonObject" -- see PythonObject -- a python object
    • "PythonObject - Thing" -- see PythonObject -- a python object
    • "PythonObject / PythonObject" -- see PythonObject -- a python object
    • "PythonObject / Thing" -- see PythonObject -- a python object
    • "PythonObject // PythonObject" -- see PythonObject -- a python object
    • "PythonObject // Thing" -- see PythonObject -- a python object
    • "PythonObject << PythonObject" -- see PythonObject -- a python object
    • "PythonObject << Thing" -- see PythonObject -- a python object
    • "PythonObject == PythonObject" -- see PythonObject -- a python object
    • "PythonObject == Thing" -- see PythonObject -- a python object
    • "PythonObject >> PythonObject" -- see PythonObject -- a python object
    • "PythonObject >> Thing" -- see PythonObject -- a python object
    • "PythonObject ? PythonObject" -- see PythonObject -- a python object
    • "PythonObject ? Thing" -- see PythonObject -- a python object
    • "PythonObject ^ PythonObject" -- see PythonObject -- a python object
    • "PythonObject ^ Thing" -- see PythonObject -- a python object
    • "PythonObject ^^ PythonObject" -- see PythonObject -- a python object
    • "PythonObject ^^ Thing" -- see PythonObject -- a python object
    • "PythonObject | PythonObject" -- see PythonObject -- a python object
    • "PythonObject | Thing" -- see PythonObject -- a python object
    • "PythonObject and PythonObject" -- see PythonObject -- a python object
    • "PythonObject and Thing" -- see PythonObject -- a python object
    • "PythonObject or PythonObject" -- see PythonObject -- a python object
    • "PythonObject or Thing" -- see PythonObject -- a python object
    • "PythonObject xor PythonObject" -- see PythonObject -- a python object
    • "PythonObject xor Thing" -- see PythonObject -- a python object
    • "Thing % PythonObject" -- see PythonObject -- a python object
    • "Thing & PythonObject" -- see PythonObject -- a python object
    • "Thing * PythonObject" -- see PythonObject -- a python object
    • "Thing + PythonObject" -- see PythonObject -- a python object
    • "Thing - PythonObject" -- see PythonObject -- a python object
    • "Thing / PythonObject" -- see PythonObject -- a python object
    • "Thing // PythonObject" -- see PythonObject -- a python object
    • "Thing << PythonObject" -- see PythonObject -- a python object
    • "Thing == PythonObject" -- see PythonObject -- a python object
    • "Thing >> PythonObject" -- see PythonObject -- a python object
    • "Thing ? PythonObject" -- see PythonObject -- a python object
    • "Thing ^ PythonObject" -- see PythonObject -- a python object
    • "Thing ^^ PythonObject" -- see PythonObject -- a python object
    • "Thing | PythonObject" -- see PythonObject -- a python object
    • "Thing and PythonObject" -- see PythonObject -- a python object
    • "Thing or PythonObject" -- see PythonObject -- a python object
    • "Thing xor PythonObject" -- see PythonObject -- a python object
    • "PythonObject @@ Thing = Thing" -- see setattr -- set an attribute of a python object
    • "setattr(PythonObject,String,Thing)" -- see setattr -- set an attribute of a python object
    • "PythonObject _ Thing = Thing" -- see setitem -- set elements of mutable python sequences
    • "setitem(PythonObject,Thing,Thing)" -- see setitem -- set elements of mutable python sequences
    • "PythonObject Thing" -- see toFunction -- convert callable python objects to Macaulay2 functions
    • "toFunction(PythonObject)" -- see toFunction -- convert callable python objects to Macaulay2 functions
    • "toPython(Boolean)" -- see toPython -- convert Macaulay2 things to Python objects
    • "toPython(CC)" -- see toPython -- convert Macaulay2 things to Python objects
    • "toPython(Constant)" -- see toPython -- convert Macaulay2 things to Python objects
    • "toPython(HashTable)" -- see toPython -- convert Macaulay2 things to Python objects
    • "toPython(List)" -- see toPython -- convert Macaulay2 things to Python objects
    • "toPython(Nothing)" -- see toPython -- convert Macaulay2 things to Python objects
    • "toPython(PythonObject)" -- see toPython -- convert Macaulay2 things to Python objects
    • "toPython(QQ)" -- see toPython -- convert Macaulay2 things to Python objects
    • "toPython(RR)" -- see toPython -- convert Macaulay2 things to Python objects
    • "toPython(Sequence)" -- see toPython -- convert Macaulay2 things to Python objects
    • "toPython(Set)" -- see toPython -- convert Macaulay2 things to Python objects
    • "toPython(String)" -- see toPython -- convert Macaulay2 things to Python objects
    • "toPython(ZZ)" -- see toPython -- convert Macaulay2 things to Python objects
    • value(PythonObject) -- convert python objects to Macaulay2 things
  • Symbols
    • dict (missing documentation)
    • eval (missing documentation)
    • expr (missing documentation)
    • Preprocessor (missing documentation)
    • stmt (missing documentation)
    • stmtexpr (missing documentation)
    • symbols (missing documentation)
    • val (missing documentation)
    • valuestring (missing documentation)

For the programmer

The object Python is a package.