-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path07_containers.ring
More file actions
52 lines (43 loc) · 1.14 KB
/
07_containers.ring
File metadata and controls
52 lines (43 loc) · 1.14 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
/*
07 - Python Containers
Create and work with Python lists, dicts, and tuples.
*/
load "python.ring"
py_init()
# ---- Lists ----
? "=== Lists ==="
mylist = py_list([10, 20, 30, 40, 50])
? "List: " + py_str(mylist)
? "Type: " + py_type(mylist)
? "Len: " + py_len(mylist)
# Call list methods
py_call_method(mylist, "append", [60])
py_call_method(mylist, "reverse", [])
? "After append(60) + reverse(): " + py_str(mylist)
# Empty list
empty = py_list([])
? "Empty list len: " + py_len(empty)
# ---- Dicts ----
? ""
? "=== Dicts ==="
mydict = py_dict([["name", "Ring"], ["version", version()], ["year", 2016]])
? "Dict: " + py_str(mydict)
? "Type: " + py_type(mydict)
? "Len: " + py_len(mydict)
# Get a value via Python
py_set("_d", py_value(mydict))
py_exec("_name = _d['name']")
? "dict['name'] = " + py_get("_name")
# ---- Tuples ----
? ""
? "=== Tuples ==="
mytuple = py_tuple([1, 2, 3])
? "Tuple: " + py_str(mytuple)
? "Type: " + py_type(mytuple)
? "Len: " + py_len(mytuple)
# ---- Constants ----
? ""
? "=== Constants ==="
? "None type: " + py_type(py_none())
? "True value: " + py_value(py_true())
? "False value:" + py_value(py_false())