Changes between Version 1 and Version 2 of Python API

Show
Ignore:
Timestamp:
09/20/13 14:53:23 (11 years ago)
Author:
jorisborgdorff
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Python API

    v1 v2  
    1616help(muscle) 
    1717}}} 
     18 
     19The API includes the following functions: 
     20{{{ 
     21muscle.init(sys.argv) 
     22muscle.finalize() 
     23 
     24muscle.send(portName, data, [muscle.datatype]) 
     25muscle.receive(portName, [muscle.datatype]) 
     26 
     27muscle.will_stop() 
     28muscle.kernel_name() 
     29muscle.tmp_path() 
     30muscle.has_property(propName) 
     31muscle.get_property(propName) 
     32 
     33muscle.log(msg) 
     34muscle.fine(msg) 
     35muscle.warning(msg) 
     36muscle.severe(msg) 
     37}}} 
     38These functions behave just like their [wiki:"C++ API" C++ counterparts], except `init`, `send` and `receive`. For `init`, first run `import sys` and then `muscle.init(sys.argv)`. Send will accept a sequence of objects, given a muscle datatype. The following datatypes are recognized: 
     39|= Object |= Python data type |= C data type | 
     40| muscle.int | sequence of `int` | 32-bit `int` | 
     41| muscle.long | sequence of `int` | 64-bit `long` | 
     42| muscle.float | sequence of `double` | 32-bit `float` | 
     43| muscle.double | sequence of `double` | 64-bit `double` | 
     44| muscle.boolean | sequence of `bool` | `bool` | 
     45| muscle.raw | `bytearray` | `char *` | 
     46| muscle.string | `str` | `const char *` | 
     47 
     48The first five data types take any sequence, as long as the Python datatype that is contained matches. In some cases, it may be necessary to recreate a NumPy array so that the canonical Python datatypes are used. For example, with `int`: 
     49{{{ 
     50import numpy as np 
     51import muscle 
     52 
     53data = np.zeros(100, np.int) 
     54muscle.send([int(d) for d in data], 'out', muscle.int) 
     55}}}