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

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 pythonValue "[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.6 of Python.

Citation

If you have used this package in your research, please cite it as follows:

@misc{PythonSource,
  title = {{Python: interface to Python. Version~0.6}},
  author = {Daniel R. Grayson and Doug Torrance},
  howpublished = {A \emph{Macaulay2} package available at
    \url{https://github.com/Macaulay2/M2/tree/master/M2/Macaulay2/packages}}
}

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
    • objectType -- type of a python object
    • pythonHelp (missing documentation)
    • pythonValue -- 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
    • ?? PythonObject (missing documentation)
    • abs(PythonObject) -- absolute value of a python object
    • addPyToM2Function(List,Function,String) -- see addPyToM2Function -- convenience function for adding value hooks
    • addPyToM2Function(String,Function,String) -- see addPyToM2Function -- convenience function for adding value hooks
    • ceiling(PythonObject) -- ceiling of a python object
    • context(String) (missing documentation)
    • describe(PythonObject) (missing documentation)
    • expression(PythonObject) (missing documentation)
    • floor(PythonObject) -- floor of a python object
    • 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
    • help(PythonObject) -- documentation for python object
    • import(String) -- see import -- import a Python module
    • isMember(PythonObject,PythonObject) -- see isMember(Thing,PythonObject) -- test membership in a python object
    • isMember(Thing,PythonObject) -- test membership in a python object
    • iterator(PythonObject) -- get iterator of iterable python object
    • length(PythonObject) -- returns the length of a python object
    • net(PythonObject) (missing documentation)
    • next(PythonObject) -- retrieve the next item from a python iterator
    • + PythonObject -- see PythonObject -- a python object
    • - PythonObject -- 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 ^^ 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 | 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 (missing documentation)
    • PythonObject &= Thing (missing documentation)
    • PythonObject *= Thing (missing documentation)
    • PythonObject += Thing (missing documentation)
    • PythonObject -= Thing (missing documentation)
    • PythonObject //= Thing (missing documentation)
    • PythonObject /= Thing (missing documentation)
    • PythonObject <<= Thing (missing documentation)
    • PythonObject >>= Thing (missing documentation)
    • PythonObject @= Thing (missing documentation)
    • PythonObject ^= Thing (missing documentation)
    • PythonObject ^^= Thing (missing documentation)
    • PythonObject |= Thing (missing documentation)
    • PythonObject ~ -- bitwise not of a python object
    • pythonValue(Sequence) -- see pythonValue -- execute Python source code from a string
    • pythonValue(String) -- see pythonValue -- execute Python source code from a string
    • quotientRemainder(PythonObject,PythonObject) -- quotient and remainder of python objects
    • quotientRemainder(PythonObject,Thing) -- see quotientRemainder(PythonObject,PythonObject) -- quotient and remainder of python objects
    • quotientRemainder(Thing,PythonObject) -- see quotientRemainder(PythonObject,PythonObject) -- quotient and remainder of python objects
    • round(PythonObject) -- see round(ZZ,PythonObject) -- round a python object
    • round(PythonObject,PythonObject) -- see round(ZZ,PythonObject) -- round a python object
    • round(ZZ,PythonObject) -- round 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
    • texMath(PythonObject) (missing documentation)
    • toExternalString(PythonObject) (missing documentation)
    • 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(Function) -- see toPython -- convert Macaulay2 things to Python objects
    • toPython(HashTable) -- 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(VisibleList) -- see toPython -- convert Macaulay2 things to Python objects
    • toPython(ZZ) -- see toPython -- convert Macaulay2 things to Python objects
    • toString(PythonObject) (missing documentation)
    • truncate(PythonObject) -- truncate a python object
    • 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)
  • Mutable symbols
    • dict (missing documentation)
    • eval (missing documentation)
    • expr (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, defined in Python.m2, with auxiliary files in Python/.


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