source: orange/orange/doc/reference/pythonvariable1.py @ 6538:a5f65d7f0b2c

Revision 6538:a5f65d7f0b2c, 1.0 KB checked in by Mitar <Mitar@…>, 4 years ago (diff)

Made XPM version of the icon 32x32.

Line 
1# Description: Shows how to construct and use PythonVariables
2# Category:    basic classes
3# Classes:     PythonVariable
4# Uses:       
5# Referenced:  pythonvariable.htm
6
7# xtest: RANDOM
8
9import orange
10
11data = orange.ExampleTable("lenses")
12
13newattr = orange.PythonVariable("foo")
14data.domain.addmeta(orange.newmetaid(), newattr)
15
16data[0]["foo"] = ("a", "tuple")
17data[1]["foo"] = "a string"
18
19# Could, but won't do this; the script is also used
20# in regression tests and printing the pointer would
21# cause a mismatch btw Win, Linux and Mac version;
22# printing the module would cause a mismatch in the path
23# data[2]["foo"] = orange
24# data[3]["foo"] = data
25
26for i in range(4):
27    print data[i]
28print
29
30def extolist(ex, wh=0):
31#    return orange.PythonValue(map(int, ex))
32    return map(int, ex)
33
34listvar = orange.PythonVariable("a_list")
35listvar.getValueFrom = extolist
36listvar.getValueFrom.classVar = listvar
37
38newdomain = orange.Domain(data.domain.attributes + [listvar], data.domain.classVar)
39newdata = orange.ExampleTable(newdomain, data)
40for i in newdata:
41    print i
42
Note: See TracBrowser for help on using the repository browser.