Skip to content

Commit 77d1d36

Browse files
committed
update doc add python basic package usage
1 parent a7bdf0b commit 77d1d36

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

docs/doc/en/basic/python.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,18 @@ Once you have acquired the basic knowledge, you can start using MaixPy for progr
5656
If you have never dealt with programming before, you will need to start learning Python from scratch. Python is also quite suitable as an introductory language. You can search for video tutorials for specific guidance.
5757

5858
After mastering the basic syntax, you will be able to use MaixPy for programming by following examples provided.
59+
60+
61+
### Using Built-in Packages
62+
63+
Python comes with many commonly used packages and APIs built-in, so if you encounter any issues, you can search for “Python using xxxx” and you might find a solution right away. This applies to various common tasks, such as file handling, networking, system operations, algorithms, and more.
64+
65+
For example:
66+
For those who are new to Python and have only dabbled in basic microcontroller development, they might wonder why there are no examples in the documentation for reading and writing to SD/TF cards. The reason is that a file system is already running on the SD/TF card by default, so you can use Python’s file handling APIs to read and write files directly on the SD card:
67+
68+
```python
69+
with open("/root/a.txt", "r") as f:
70+
content = f.read()
71+
print(content)
72+
```
73+

docs/doc/en/faq.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,18 @@ This occurs because the program encountered an error and exited abnormally. You
212212
### Method 2:
213213
If the application is written in Python, use **MaixVision** to run the source code directly, examine the runtime errors, and make corrections. Be aware that errors may not be at the last line, so inspect the logs carefully from the end upward.
214214

215+
216+
### How to Read/Write to SD/TF Cards and Save Data to Them
217+
218+
MaixPy is based on Linux and standard Python 3. The operating system and file system both run on the SD/TF card, so reading and writing data is done through the file system.
219+
220+
You can use Python’s standard APIs to perform file operations. For example, to read a file:
221+
222+
```python
223+
with open("/root/a.txt", "r") as f:
224+
content = f.read()
225+
print(content)
226+
```
227+
228+
Similarly, other functions that are not covered in the documentation can be searched to check if they are included in Python’s built-in libraries, which you can call directly.
229+

docs/doc/zh/basic/python.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,18 @@ Python 是一门解释性、面向对象、动态类型的高级编程语言。
6060

6161
在学会了基础语法后,就能按照例程使用 MaixPy 编程了。
6262

63+
64+
## 使用内置的软件包
65+
66+
Python 已经内置了很多常用的软件包和 API,所以遇到什么问题可以搜索`“Python 使用 xxxx"`说不定就能直接能用。
67+
比如常见的 文件、网络、系统、算法等等。
68+
69+
举个例子:
70+
对于没有接触过 Python, 只涉略过初级的单片机开发的同学来说,可能会有些疑问为什么文档没有读写 SD/TF 卡的例程:
71+
因为默认就有文件系统跑在 SD/TF 卡上的,只要用 Python 的文件操作 API 就能读写 SD 卡中的文件:
72+
```python
73+
with open("/root/a.txt", "r") as f:
74+
content = f.read()
75+
print(content)
76+
```
77+

docs/doc/zh/faq.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,16 @@ ImportError: arg(): could not convert default argument into a Python object (typ
204204
* 方法二:如果是 Python 编写的应用,使用 MaixVision 运行源码查看运行错误并修正,注意报错可能不在最后一行,可以从后往前仔细查找。
205205

206206

207+
## 如何读写 SD/TF 卡,保存数据到 SD/TF 卡
208+
209+
MaixPy 基于 Linux 和 标准 Python3,操作系统在 SD/TF 卡上,同时文件系统也在 SD 卡上,保存和读取数据都从文件系统操作。
210+
使用 Python 的标准 API 即可操作,比如读取文件:
211+
```python
212+
with open("/root/a.txt", "r") as f:
213+
content = f.read()
214+
print(content)
215+
```
216+
217+
类似的,其它在文档中没介绍的功能可以尝试搜一艘是不是 Python 自带的库,可以直接调用。
218+
219+

0 commit comments

Comments
 (0)