getpythonvar

Imports the Python variable value to the OML variable.

Syntax

value=getpythonvar(PythonVariableName)

[value,status]=getpythonvar(PythonVariableName)

[value,status,errorMessage]=getpythonvar(PythonVariableName)

Inputs

PythonVariableName
Python variable name.
Type: string

Outputs

status
Status of the script executed.
1
success
0
failure
Type: number
errorMessage
Error message indicating the failure.
Type: string
value
OML variable.
Type:
Python Variable Type OML Variable Type Limitations
Bool Logical  
long, Float Number  
Complex Complex  
List Cell (1,n) n:number of elements in list Does not support if list contains Dict (with limitation), Tupple, Set
dict Struct Supports only if keys in dict are string or char.
Numpy - array, matrix Matrix Data types supported in OML: matrix, Bool, Int, long, Float, Complex.
Numpy Ndarray ND Matrix Data types supported in OML: matrix, Bool, Int, long, Float, Complex.

Examples

Importing logical data from Python:

evalpythonscript('pofalse = False'); 
[value, status, errormessage] = getpythonvar('pofalse')

value = 0
status = 1
errormessage =

Importing integer data from Python:

evalpythonscript('point = 999'); 
[value, status, errormessage] = getpythonvar('point')

value = 999
status = 1
errormessage =

Importing precision data from Python:

evalpythonscript('pofloat=9.99');
[value, status, errormessage] = getpythonvar('pofloat')

value = 9.99
status = 1
errormessage =

Importing complex data from Python:

evalpythonscript('pocomp=9+9j');
[value, status, errormessage] = getpythonvar('pocomp')

value = 9 + 9i
status = 1
errormessage =

Importing string data from Python:

evalpythonscript('postring="String Data"');
[value, status, errormessage] = getpythonvar('postring')

value = String Data
status = 1
errormessage =

Importing list data from Python:

evalpythonscript('polist  = ["a","b","c","d"]');
[value, status, errormessage] = getpythonvar('polist')

value = 
{
[1,1] a
[1,2] b
[1,3] c
[1,4] d
}
status = 1
errormessage =

Importing dictionary data from Python:

evalpythonscript('polist  = ["a","b","c","d"]');
evalpythonscript('podict = {"key1":1,"key2" : polist }');
[value, status, errormessage] = getpythonvar('podict')

value = struct [
key1: 1
key2: 
{
[1,1] a
[1,2] b
[1,3] c
[1,4] d
]
status = 1
errormessage =

Importing matrix data from Python:

evalpythonscript('import numpy as np');
evalpythonscript('pomatrix = np.matrix("1 2; 3 4")');
[value, status, errormessage] = getpythonvar('pomatrix')

value = [Matrix] 2 x 2
1 2
3 4
status = 1
errormessage =

Importing nd matrix data from Python:

evalpythonscript('import numpy as np');
evalpythonscript('pondarray = np.arange(720).reshape(6,4,2,3,5)');
[value, status, errormessage] = getpythonvar('pondarray')

value = 
slice(:, :, 1, 1, 1) = 
[Matrix] 6 x 4
0 30 60 90
120 150 180 210
240 270 300 330
360 390 420 450
480 510 540 570
600 630 660 690
slice(:, :, 1, 1, 2) = 
[Matrix] 6 x 4 Row[1] Columns[1:4]
1 31 61 91
[Matrix] 6 x 4 Rows[2:6] Columns[1:4]
121 151 181 211
241 271 301 331
361 391 421 451
481 511 541 571
601 631 661 691
…….
slice(:, :, 2, 3, 4) = 
[Matrix] 6 x 4
28 58 88 118
148 178 208 238
268 298 328 358
388 418 448 478
508 538 568 598
628 658 688 718
slice(:, :, 2, 3, 5) = 
[Matrix] 6 x 4 Row[1] Columns[1:4]
29 59 89 119
[Matrix] 6 x 4 Rows[2:6] Columns[1:4]
149 179 209 239
269 299 329 359
389 419 449 479
509 539 569 599
629 659 689 719

status = 1
errormessage =