editor

๐Ÿ–‹ Open the default text editor ๐Ÿ–‹

22 ไธช็‰ˆๆœฌ Python >=3.10
ๅฎ‰่ฃ…
pip install editor
poetry add editor
pipenv install editor
conda install editor
ๆ่ฟฐ

๐Ÿ–‹ editor - Open a text editor ๐Ÿ–‹

editor opens the default text editor or your favorite editor to edit an existing file, a new file, or a tempfile, blocks while the user edits text, then returns the contents of the file.

You can pass a parameter editor= to specify an editor or leave it empty, in which case the editor is:

  • The contents of the environment variable VISUAL, if it's set, otherwise:
  • The the contents of the environment variable EDITOR, if it's set, otherwise:
  • The string 'Notepad', if the code is running on Windows, otherwise:
  • The string 'vim'

Example 1: Using a temporary file

If no filename is provided, a temporary file gets edited, and its contents returned.

import editor

comments = editor.editor(text='Comments here\n\n')
# Pop up the default editor with a tempfile containing "Comments here",
# then return the contents and delete the tempfile.

Example 2: Using a named file

If a filename is provided, then that file gets edited.

import os

FILE = 'file.txt'
assert not os.path.exists(FILE)

comments = editor.editor(text=MESSAGE, filename=FILE)
# Pop up an editor for a new FILE containing MESSAGE, user edits
# This file is saved when the user exits the editor.

assert os.path.exists(FILE)

# You can edit an existing file too, and select your own editor.
comments2 = editor.editor(filename=FILE, editor='emacs -nw')

API Documentation

็‰ˆๆœฌๅˆ—่กจ
1.8.0 2026-05-09
1.7.0 2026-02-03
1.6.6 2024-01-25
1.6.5 2024-01-06
1.6.4 2024-01-06
1.6.3 2024-01-05
1.6.2 2024-01-05
1.6.1 2024-01-04
1.6.0 2024-01-04
1.5.0 2023-12-29
1.4.1 2023-12-28
1.4.0 2023-10-05
1.3.0 2023-02-25
1.2.1 2021-02-26
1.2.0 2020-11-18
1.1.0 2020-11-17
1.0.1 2020-11-16
1.0.0 2020-10-11
0.10.2 2020-10-08
0.10.1 2020-09-21
0.10.0 2020-09-06
0.9.0 2020-07-22