SummerGift 6 лет назад
Родитель
Сommit
7b8b7fbb15

+ 26 - 0
examples/basic/array.py

@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2006-2019, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: MIT License
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2019-06-13     SummerGift   first version
+ */
+
+import array
+
+a = array.array('i', [2, 4, 1, 5])
+b = array.array('f')
+print(a)
+print(b)
+
+a = array.array('f', [3, 6])
+print(a)
+a.append(7.0)
+print(a)
+
+a = array.array('i', [1, 2, 3])
+b = array.array('i', [4, 5])
+a.extend(b)
+print(a)

+ 17 - 0
examples/basic/random.py

@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2006-2019, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: MIT License
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2019-06-13     SummerGift   first version
+ */
+
+import random
+
+for j in range(0, 2):
+    random.seed(13)         #指定随机数种子
+    for i in range(0, 10):  #生成0到10范围内的随机序列
+        print(random.randint(1, 10))
+    print("end")

+ 15 - 0
examples/basic/rtthread.py

@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2006-2019, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: MIT License
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2019-06-13     SummerGift   first version
+ */
+
+import rtthread
+
+print(rtthread.is_preempt_thread())       # determine if code is running in a preemptible thread
+print(rtthread.current_tid() )            # current thread id
+rtthread.stacks_analyze()                 # show thread information

+ 18 - 0
examples/basic/sys.py

@@ -0,0 +1,18 @@
+/*
+ * Copyright (c) 2006-2019, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: MIT License
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2019-06-13     SummerGift   first version
+ */
+
+import sys
+
+print(sys.version)
+print(sys.version_info)
+print(sys.path)
+print(sys.__name__)
+print(sys.platform)
+print(sys.byteorder)

+ 29 - 0
examples/basic/ucollections.py

@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2006-2019, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: MIT License
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2019-06-13     SummerGift   first version
+ */
+
+from ucollections import namedtuple
+
+MyTuple = namedtuple("MyTuple", ("id", "name"))
+t1 = MyTuple(1, "foo")
+t2 = MyTuple(2, "bar")
+print(t1.name)
+assert t2.name == t2[1]
+ucollections.OrderedDict(...)
+
+from ucollections import OrderedDict
+
+# To make benefit of ordered keys, OrderedDict should be initialized
+# from sequence of (key, value) pairs.
+d = OrderedDict([("z", 1), ("a", 2)])
+# More items can be added as usual
+d["w"] = 5
+d["b"] = 3
+for k, v in d.items():
+    print(k, v)

+ 20 - 0
examples/basic/utime.py

@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2006-2019, RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: MIT License
+ *
+ * Change Logs:
+ * Date           Author       Notes
+ * 2019-06-13     SummerGift   first version
+ */
+
+import utime
+
+utime.sleep(1)                                    # sleep for 1 second
+utime.sleep_ms(500)                               # sleep for 500 milliseconds
+utime.sleep_us(10)                                # sleep for 10 microseconds
+start = utime.ticks_ms()                          # get value of millisecond counter
+delta = utime.ticks_diff(utime.ticks_ms(), start) # compute time difference
+print(utime.ticks_add(utime.ticks_ms(), -100))
+print(utime.ticks_add(0, -1))
+