source: orange/Orange/testing/regression/tests_20/reference_pythonvariable2c.py @ 9952:986e9cd806f4

Revision 9952:986e9cd806f4, 833 bytes checked in by Miha Stajdohar <miha.stajdohar@…>, 2 years ago (diff)

Tests moved and renamed from orange 20.

Line 
1import orange, time
2
3class DateVariable(orange.PythonVariable):
4    def str2val(self, str):
5        return time.strptime(str, "%b %d %Y")
6
7    def val2str(self, val):
8        return time.strftime("%b %d %Y (%a)", val)
9
10    def filestr2val(self, str, example):
11        if str == "unknown":
12            return orange.PythonValueSpecial(orange.ValueTypes.DK)
13        return DateValue(time.strptime(str, "%m/%d/%Y"))
14
15    def val2filestr(self, val, example):
16        return time.strftime("%m/%d/%Y", val)
17
18birth = DateVariable("birth")
19val = birth("Aug 19 2003")
20print val
21
22data = orange.ExampleTable("lenses")
23
24newdomain = orange.Domain(data.domain.attributes + [birth], data.domain.classVar)
25newdata = orange.ExampleTable(newdomain, data)
26
27newdata[0]["birth"] = "Aug 19 2003"
28print newdata[0]
29
30orange.saveTabDelimited("del2", newdata)
Note: See TracBrowser for help on using the repository browser.