GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - eastyou/morsecode: 摩尔斯电码:命令行编解码与可打印练习卡

BranchesTags
Open more actions menu

Latest commit

 

History

2 Commits
2 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
examples
examples
 
 
morsecode
morsecode
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
pyproject.toml
pyproject.toml
 
 

Repository files navigation

morsecode

CI License: MIT Python

零依赖的摩尔斯电码命令行工具:文本与电码互转,一条命令生成 A4 可打印练习卡,适合信息科技课与社团活动。只用 Python 3.9+ 标准库,不联网,打印即用。

特性

  • 双向转换:--text 编码、--decode 解码,字母间自动空一格,单词间用 / 分隔
  • 完整字符表:A–Z(不区分大小写)、0–9 与 13 个常用标点
  • 严格校验:不支持的字符(含中文)用中文报错,并指出字符与位置;非法码元同样定位到第几个码元
  • 练习卡:从 66 个常见英文单词中不重复抽题,A4 纵向每页 3 张,附参考答案页
  • 可复现:--seed 固定随机种子,同一份练习可重复打印
  • 自包含页面:HTML/CSS 内置,无外部字体、脚本或图片;屏幕自适应,打印清晰
  • 117 个单元测试:覆盖编码表、大小写、多空格、往返转换、非法输入、抽题去重、页数与 CLI 退出码

安装

pip install morsecode

也可以直接下载源码,在项目目录里运行:

python -m morsecode --help

用法

编码

python -m morsecode --text "SOS 2026"

输出:

... --- ... / ..--- ----- ..--- -....

解码

python -m morsecode --decode "... --- ... / -.-"

输出:

SOS K

生成练习卡

python -m morsecode --card --count 12 --seed 42 --title 摩尔斯练习卡 -o examples/摩尔斯练习卡.html

打开 HTML 后按 Ctrl/Cmd + P,纸张选 A4 纵向、边距选「无」即可打印。前几页是练习卡,最后一页是参考答案。

参数

参数 说明 默认
--text 要编码的文本 与 --decode、--card 三选一
--decode 要解码的电码 与 --text、--card 三选一
--card 生成 A4 练习卡 与 --text、--decode 三选一
--count 练习卡题目数量(6~30) 12
--seed 随机种子,相同种子得到相同题目 随机
--title 练习卡标题(最多 24 个字符) 摩尔斯练习卡
-o, --output 输出文件;编码/解码不填则打印到屏幕 编码/解码无,卡片为 摩尔斯练习卡.html

--count 与 --seed 只能和 --card 一起使用;--text、--decode、--card 必须且只能指定一个。

退出码

退出码 含义
0 成功
1 文件读写失败(如输出目录不存在)
2 参数或数据错误(如非法字符、非法码元、数量越界)

电码表

字符 电码 字符 电码 字符 电码
A .- B -... C -.-.
D -.. E . F ..-.
G --. H .... I ..
J .--- K -.- L .-..
M -- N -. O ---
P .--. Q --.- R .-.
S ... T - U ..-
V ...- W .-- X -..-
Y -.-- Z --.. 0 -----
1 .---- 2 ..--- 3 ...--
4 ....- 5 ..... 6 -....
7 --... 8 ---.. 9 ----.
. .-.-.- , --..-- ? ..--..
/ -..-. = -...- + .-.-.
- -....- ( -.--. ) -.--.-
: ---... ' .----. " .-..-.
@ .--.-.

编码时 A–Z 不区分大小写,解码结果统一为大写字母。

练习卡

  • A4 纵向,每页 3 张卡片,卡片含序号、英文单词、两条书写横线和书写提示
  • 单词从 66 个常见英文单词中不重复抽取,--seed 相同则题目与顺序完全一致
  • 未指定 --count 时默认 12 题,即 4 页练习卡加 1 页答案
  • 参考答案单独成页,列出每题单词与完整电码,方便教师核对或单独留存
  • 页面无任何网络资源;窄屏下自动改为单列,不出现横向滚动条

项目结构

morsecode/
├── morsecode/
│   ├── __init__.py   # 包导出与版本号
│   ├── __main__.py   # python -m morsecode
│   ├── cli.py        # 命令行参数、退出码与文件读写
│   ├── model.py      # 电码表、编解码、校验与抽题
│   └── render.py     # A4 练习卡 HTML/CSS 渲染
├── tests/            # 117 个单元测试
├── examples/         # 示例练习卡
├── .github/workflows/ci.yml
├── pyproject.toml
└── README.md

测试

python -m unittest discover -s tests

CI 在 Ubuntu、macOS、Windows 上运行 Python 3.10 与 3.13,并额外覆盖 Ubuntu 22.04 + Python 3.9;单测之后执行编码、解码、练习卡三条命令的冒烟与内容断言。

许可证

MIT © 2026 eastyou

About

摩尔斯电码:命令行编解码与可打印练习卡

Topics

clidecodereducationencodermorse-codeprintpython

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.