source: orange/Orange/doc/reference/pythonvariable2b.py @ 9671:a7b056375472

Revision 9671:a7b056375472, 867 bytes checked in by anze <anze.staric@…>, 2 years ago (diff)

Moved orange to Orange (part 2)

Line 
1import orange
2
3import time
4
5class DateValue(orange.SomeValue):
6    def __init__(self, date):
7        self.date = date
8       
9    def __str__(self):
10        return time.strftime("%b %d %Y (%a)", self.date)
11
12    def __cmp__(self, other):
13        return cmp(self.date, other.date)
14   
15class DateVariable(orange.PythonVariable):
16    def str2val(self, str):
17        return DateValue(time.strptime(str, "%b %d %Y"))
18
19birth = DateVariable("birth")
20val = birth("Aug 19 2003")
21print val
22
23data = orange.ExampleTable("lenses")
24
25newdomain = orange.Domain(data.domain.attributes + [birth], data.domain.classVar)
26newdata = orange.ExampleTable(newdomain, data)
27
28newdata[0]["birth"] = "Aug 19 2003"
29newdata[1]["birth"] = "Jan 12 1998"
30newdata[2]["birth"] = "Sep 1 1995"
31newdata[3]["birth"] = "May 25 2001"
32newdata.sort("birth")
33print "\nSorted data"
34for i in newdata:
35    print i
Note: See TracBrowser for help on using the repository browser.