Top
Back: polytope
Forward: pyobject declarations
FastBack:
FastForward: countedref
Up: Data types
Top: Singular Manual
Contents: Table of Contents
Index: Index
About: About this document

4.27 pyobject

The pyobject is a black box data type in for handling objects from the programming language python. It needs the python support of to be installed.

Together with some basic operations and functions, pyobject instances access python functionality from within and store the results for re-use:

Note that this feature is automatically loaded on demand when initializing an object of type pyobject. For accessing pyobject-related functions before using any python object, please type LIB("pyobject.so"); at the prompt.

 
pyobject pystr = "Hello";
==> no pyobject support
pyobject pyint = 2;
string singstr = string(pystr + " World!");
==>    ? `pyobject` + `string` failed
==>    ? expected `string` + `string`
==>    ? expected `ring` + `string`
==>    ? error occurred in or before ./examples/pyobject.sing line 3: `string\
    singstr = string(pystr + " World!");`
==>    ? expected string-expression. type 'help string;'
singstr;
==>    ? `singstr` is undefined
==>    ? error occurred in or before ./examples/pyobject.sing line 4: `singst\
   r;`
pystr + pyint;  // Error: not possible
==>    ? `pyobject` + `pyobject` failed
==>    ? error occurred in or before ./examples/pyobject.sing line 5: `pystr \
   + pyint;  // Error: not possible`
pystr * pyint;  // But this is allowed,
==>    ? `pyobject` * `pyobject` failed
==>    ? error occurred in or before ./examples/pyobject.sing line 6: `pystr \
   * pyint;  // But this is allowed,`
pystr * 3;      // as well as this;
==>    ? `pyobject` * `int` failed
==>    ? expected `int` * `int`
==>    ? expected `matrix` * `int`
==>    ? expected `bigintmat` * `int`
==>    ? expected `intvec` * `int`
==>    ? expected `intmat` * `int`
==>    ? error occurred in or before ./examples/pyobject.sing line 7: `pystr \
   * 3;      // as well as this;`

python_run("def newfunc(*args): return list(args)");  // syncs contexts!
==>    ? `python_run` is not defined
==>    ? error occurred in or before ./examples/pyobject.sing line 9: `python\
   _run("def newfunc(*args): return list(args)");  // syncs contexts!`
newfunc(1, 2, 3);          // newfunc also knowd to SINGULAR
==>    ? `newfunc(1,2,3)` is undefined
==>    ? error occurred in or before ./examples/pyobject.sing line 10: `newfu\
   nc(1, 2, 3);          // newfunc also knowd to SINGULAR`

def pylst = python_eval("[3, 7, 1]");
==>    ? `python_eval` is not defined
==>    ? error occurred in or before ./examples/pyobject.sing line 12: `def p\
   ylst = python_eval("[3, 7, 1]");`
proc(attrib(pylst, "sort"))(); // Access python member routines as attributes
==>    ? proc(`string`) failed
==>    ? expected proc(`proc`)
==>    ? error occurred in or before ./examples/pyobject.sing line 13: `proc(\
   attrib(pylst, "sort"))(); // Access python member routines as attributes`
==>    ? wrong type declaration. type 'help proc;'
pylst.sort();             // <- equivalent short-notation
==>    ? `pylst` is not defined
==>    ? error occurred in or before ./examples/pyobject.sing line 14: `pylst\
   .sort();             // <- equivalent short-notation`
pylst."sort"();           // <- alternative short-notation
==>    ? `pylst` is not defined
==>    ? error occurred in or before ./examples/pyobject.sing line 15: `pylst\
   ."sort"();           // <- alternative short-notation`
pylst;
==>    ? `pylst` is undefined
==>    ? error occurred in or before ./examples/pyobject.sing line 16: `pylst\
   ;`

python_import("os");       // Gets stuff from python module 'os'
==>    ? `python_import` is not defined
==>    ? error occurred in or before ./examples/pyobject.sing line 18: `pytho\
   n_import("os");       // Gets stuff from python module 'os'`
name;                      // The identifier of the operating system
==>    ? `name` is undefined
==>    ? error occurred in or before ./examples/pyobject.sing line 19: `name;\
                         // The identifier of the operating system`

4.27.1 pyobject declarations  
4.27.2 pyobject expressions  
4.27.3 pyobject operations  
4.27.4 pyobject related functions  


Top Back: polytope Forward: pyobject declarations FastBack: FastForward: countedref Up: Data types Top: Singular Manual Contents: Table of Contents Index: Index About: About this document
            User manual for Singular version 4.2.1, 2021, generated by texi2html.