File: wrap.py

package info (click to toggle)
metakit 2.4.3-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 6,468 kB
  • ctags: 3,548
  • sloc: xml: 29,455; cpp: 23,339; sh: 9,051; tcl: 1,195; python: 577; makefile: 254; ansic: 14
file content (40 lines) | stat: -rw-r--r-- 874 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Wrapping Python data as MetaKit views
#
# Expected output (3 times):
#    a      b      c
#    -----  -----  -
#    one    un     1
#    two    deux   2
#    three  trois  3
#    -----  -----  -
#    Total: 3 rows

import metakit

class C:
    def __init__(self, a, b, c):
    	self.a, self.b, self.c = a, b, c

dc = [	C ('one', 'un', 1),
	C ('two', 'deux', 2),
	C ('three', 'trois', 3)  ]

dd = [	{'a':'one', 'b':'un', 'c':1}, 
	{'a':'two', 'b':'deux', 'c':2}, 
	{'a':'three', 'b':'trois', 'c':3}  ] 

dt = [	('one', 'un', 1), 
	('two', 'deux', 2), 
	('three', 'trois', 3)  ] 

pl = [	metakit.property('S','a'),
	metakit.property('S','b'),
	metakit.property('I','c')  ]

vc = metakit.wrap(dc, pl)
vd = metakit.wrap(dd, pl)
vt = metakit.wrap(dt, pl, 1)

metakit.dump(vc, 'class objects:')
metakit.dump(vd, 'dictionary elements:')
metakit.dump(vt, 'tuples (by position):')