]> gerrit.simantics Code Review - simantics/python.git/blob - org.simantics.pythonlink/test/org/simantics/pythonlink/test/scripts/Python.sts
409d9b2001e6d8a9061260ea3b3e1267278ce4ed
[simantics/python.git] / org.simantics.pythonlink / test / org / simantics / pythonlink / test / scripts / Python.sts
1 > import "Simantics/Python"\r
2 > import "Vector"\r
3\r
4 > runPython do\r
5 >     executePythonStatement "foo = 'bar'\nd = dir()"\r
6 >     getPythonStringArrayVariable "d"\r
7 vector ["__builtins__", "__doc__", "__loader__", "__name__", "__package__", "__spec__", "foo"]\r
8 > runPython do\r
9 >     setPythonDoubleVariable "foo" 1\r
10 >     executePythonStatement "foo = foo + 1"\r
11 >     getPythonDoubleVariable "foo"\r
12 2.0\r
13 > runPython do\r
14 >     setPythonDoubleArrayVariable "foo" (vector [1.0, 2.0, 3.0])\r
15 >     executePythonStatement "foo = foo + [4.0]"\r
16 >     getPythonDoubleArrayVariable "foo"\r
17 vector [1.0, 2.0, 3.0, 4.0]\r
18 > runPython do\r
19 >     setPythonIntegerVariable "foo" 5\r
20 >     executePythonStatement "import math"\r
21 >     executePythonStatement "bar = math.factorial(foo)"\r
22 >     getPythonIntegerVariable "bar"\r
23 120\r
24 > runPython do\r
25 >     setPythonIntegerArrayVariable "foo" (vector [1, 2, 3, 4])\r
26 >     executePythonStatement "foo.append(sum(foo))"\r
27 >     getPythonIntegerArrayVariable "foo"\r
28 vector [1, 2, 3, 4, 10]\r
29 > ndarray (vector [1, 2, 3])\r
30 ndarray(3) [1.0, 2.0, 3.0]\r
31 > ndarrayM 2 2 (vector [1, 2, 3, 4])\r
32 ndarray(2x2) [1.0, 2.0, 3.0, 4.0]\r
33 > a = ndarrayN (vector [2, 2, 3]) (vector [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])\r
34 > a\r
35 ndarray(2x2x3) [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, ...]\r
36 > ndarrayDims a\r
37 vector [2, 2, 3]\r
38 > ndarrayValues a\r
39 vector [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]\r
40 > ndarrayElement a 5\r
41 6.0\r
42 > ndarrayElementN a (vector [0, 1, 2])\r
43 6.0\r
44 > runPython do\r
45 >     setPythonNDArrayVariable "foo" (ndarrayM 2 3 (vector [1, 2, 3,  4, 5, 6]))\r
46 >     executePythonStatement "bar = foo.cumsum(1)"\r
47 >     getPythonNDArrayVariable "bar"\r
48 ndarray(2x3) [1.0, 3.0, 6.0, 4.0, 9.0, 15.0]\r