Top
Back: pyobject operations
Forward: python_eval
FastBack: polytope
FastForward: countedref
Up: pyobject
Top: Singular Manual
Contents: Table of Contents
Index: Index
About: About this document

4.27.4 pyobject related functions

attrib
list, get and set attributes (class members) of a pyobject (see attrib)


Example:
 
  pyobject pystr = "Kublai Khan";

  // Additional functionality through attrib
  attrib(pystr, "__doc__");
==> "str(object='') -> string\n\nReturn a nice string representation of the o\
   bject.\nIf the argument is a string, the return value is the same object.\
   "
  proc(attrib(pystr, "count"))("K");
==> 2

  pystr."__doc__";           // <- Short notations
==> "str(object='') -> string\n\nReturn a nice string representation of the o\
   bject.\nIf the argument is a string, the return value is the same object.\
   "
  pystr.count("a");          // Even shorter (if attribute's name is valid and unused)
==> 2

  python_run("def func(): return 17");
  attrib(func);
==> ['__call__', '__class__', '__closure__', '__code__', '__defaults__', '__d\
   elattr__', '__dict__', '__doc__', '__format__', '__get__', '__getattribut\
   e__', '__globals__', '__hash__', '__init__', '__module__', '__name__', '_\
   _new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__siz\
   eof__', '__str__', '__subclasshook__', 'func_closure', 'func_code', 'func\
   _defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name']
  attrib(func, "func_name");
==> 'func'
  attrib(func, "func_name", "byAnyOtherName");
  attrib(func, "func_name");
==> 'byAnyOtherName'

killattrib
deletes an attribute from a pyobject (see killattrib)


Example:
 
LIB("pyobject.so");
python_run("def new_pyobj(): pass");
attrib(new_pyobj, "new_attr", "something");
attrib(new_pyobj, "new_attr");
==> 'something'
attrib(new_pyobj);
==> ['__call__', '__class__', '__closure__', '__code__', '__defaults__', '__d\
   elattr__', '__dict__', '__doc__', '__format__', '__get__', '__getattribut\
   e__', '__globals__', '__hash__', '__init__', '__module__', '__name__', '_\
   _new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__siz\
   eof__', '__str__', '__subclasshook__', 'func_closure', 'func_code', 'func\
   _defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name', 'new_at\
   tr']

killattrib(new_pyobj, "new_attr");
attrib(new_pyobj);
==> ['__call__', '__class__', '__closure__', '__code__', '__defaults__', '__d\
   elattr__', '__dict__', '__doc__', '__format__', '__get__', '__getattribut\
   e__', '__globals__', '__hash__', '__init__', '__module__', '__name__', '_\
   _new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__siz\
   eof__', '__str__', '__subclasshook__', 'func_closure', 'func_code', 'func\
   _defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name']

python_run
execute string-given python commands and import new symbols from python to SINGULAR's context (see python_run).
python_eval
evaluate a string-given python expression and return the result to SINGULAR (see python_eval).
python_import
import python module into SINGULAR's context (see python_import)

4.27.5 python_eval  
4.27.6 python_import  
4.27.7 python_run  

Top Back: pyobject operations Forward: python_eval FastBack: polytope FastForward: countedref Up: pyobject Top: Singular Manual Contents: Table of Contents Index: Index About: About this document
            User manual for Singular version 4.3.1, 2022, generated by texi2html.