Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改plugins下的README.md,提示导入文件的方法 #2377

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,24 +176,42 @@

## 插件编写示例

以`plugins/hello`为例,其中编写了一个简单的`Hello`插件。
以`plugins/hello`为例,其中编写了一个简单的`Hello`插件。`hello`即为插件的名称,需要自行替换为自己的插件名字。

### 1. 创建插件

在`plugins`目录下创建一个插件文件夹`hello`。然后,在该文件夹中创建``__init__.py``文件,在``__init__.py``中将其他编写的模块文件导入。在程序启动时,插件管理器会读取``__init__.py``的所有内容。



```
plugins/
└── hello
├── __init__.py
└── hello.py
├── hello.py
└── tool.py
```

``__init__.py``的内容:

```
from .hello import *
```

导入区规范:

```python
[hello.py]

import plugins.hello.tool (✅)
from .tool import * (✅)
import tool(❌)# not found for the module 'plugins.hello.tool'

import plugins.hello.tool as tool #建议这样
```



### 2. 编写插件类

在`hello.py`文件中,创建插件类,它继承自`Plugin`。
Expand Down