๐ Open the default text editor ๐
Project Links
Meta
Author: Tom Ritchford
Requires Python: >=3.8
Classifiers
License
- OSI Approved :: MIT License
Programming Language
- Python :: 3
- Python :: 3.8
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
๐ 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
Jan 25, 2024
1.6.6
Jan 06, 2024
1.6.5
Jan 06, 2024
1.6.4
Jan 05, 2024
1.6.3
Jan 05, 2024
1.6.2
Jan 04, 2024
1.6.1
Jan 04, 2024
1.6.0
Dec 29, 2023
1.5.0
Dec 28, 2023
1.4.1
Oct 05, 2023
1.4.0
Feb 25, 2023
1.3.0
Feb 26, 2021
1.2.1
Nov 18, 2020
1.2.0
Nov 17, 2020
1.1.0
Nov 16, 2020
1.0.1
Oct 11, 2020
1.0.0
Oct 08, 2020
0.10.2
Sep 21, 2020
0.10.1
Sep 06, 2020
0.10.0
Jul 22, 2020
0.9.0