Skip to content

macOS Python input() 中文退格只能删一半(libedit UTF-8 bug) #143

@toxic-19

Description

@toxic-19

在 macOS 上运行交互式输入时,输入中文字符后按退格键,只能删除最后一个字节而非整个字符。

例如输入 你好,退格一次只能删掉 字的最后一个字节,屏幕显示乱码, 字删不掉。

环境:macOS26 + Python 3.10.20

原因

  1. macOS 的 Python 解释器内置链接的是 BSD libedit,不是 GNU readline。

  2. libedit 在 canonical mode 下处理退格是按字节而非按 UTF-8 字符。中文在 UTF-8 占 3 字节,退格只删 1 字节。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions