Top
Back: Access to elements of a user defined type
Forward: pyobject declarations
FastBack: User defined types
FastForward: Functions and system variables
Up: Data types
Top: Singular Manual
Contents: Table of Contents
Index: Index
About: About this document

4.22 pyobject

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

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

 
pyobject pystr = "Hello";
pyobject pyint = 2;
string singstr = string(pystr + " World!");
singstr;
==> 'Hello World!'
pystr + pyint;  // Error: not possible
==>    ? pyobject error occured
==>    ? cannot concatenate 'str' and 'int' objects
==>    ? error occurred in or before ./examples/pyobject.sing line 5: `pystr \
   + pyint;  // Error: not possible`
pystr * pyint;  // But this is allowed,
==> 'HelloHello'
pystr * 3;      // as well as this;
==> 'HelloHelloHello'

python_run("def newfunc(*args): return list(args)");  // syncs contexts!
newfunc(1, 2, 3);          // newfunc also knowd to SINGULAR
==> [1, 2, 3]

def pylst = python_eval("[3, 7, 1]");
proc(attrib(pylst, "sort"))(); // Access python member routines as attributes
pylst.sort();             // <- equivalent short-notation
pylst."sort"();           // <- alternative short-notation
pylst;
==> [1, 3, 7]

python_import("os");       // Gets stuff from python module 'os'
name;                      // The identifier of the operating system
==> 'posix'

4.22.1 pyobject declarations  
4.22.2 pyobject expressions  
4.22.3 pyobject operations  
4.22.4 pyobject related functions  


Top Back: Access to elements of a user defined type Forward: pyobject declarations FastBack: User defined types FastForward: Functions and system variables Up: Data types Top: Singular Manual Contents: Table of Contents Index: Index About: About this document
            User manual for Singular version 3-1-3, March 2011, generated by texi2html.