Programmatically open an editor, capture the result
Project description
python-editor revival fork for dob (because python-editor has not been released in many years).
Original README
python-editor is a library that provides the editor module for programmatically interfacing with your system’s $EDITOR.
Examples
import editor
commit_msg = editor.edit(contents=b"# Enter commit message here")
Opens an editor, prefilled with the contents, # Enter commit message here. When the editor is closed, returns the contents (bytes) in variable commit_msg. Note that the argument to contents needs to be a bytes object on Python 3.
editor.edit(file="README.txt")
Opens README.txt in an editor. Changes are saved in place. If there is a contents argument then the file contents will be overwritten.
editor.edit(..., use_tty=True)
Opens the editor in a TTY. This is usually done in programs which output is piped to other programs. In this case the TTY is used as the editor’s stdout, allowing interactive usage.
How it Works
editor first looks for the ${EDITOR} environment variable. If set, it uses the value as-is, without fallbacks.
If no $EDITOR is set, editor will search through a list of known editors, and use the first one that exists on the system.
For example, on Linux, editor will look for the following editors in order:
vim
emacs
nano
When calling editor.edit, an editor will be opened in a subprocess, inheriting the parent process’s stdin, stdout.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file python_editor_hotoffthehamster-1.1.1.tar.gz
.
File metadata
- Download URL: python_editor_hotoffthehamster-1.1.1.tar.gz
- Upload date:
- Size: 29.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e40a2b258c2cbb5678338d52445c20fe0c7ef0737c0c14392572c41ba99072be |
|
MD5 | f3c1d2428c059b405063e52ef9e2ddd8 |
|
BLAKE2b-256 | 33edeafcaa419910b7ac3e0f7393855e227d6919d42df9aff291692d72807242 |
File details
Details for the file python_editor_hotoffthehamster-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: python_editor_hotoffthehamster-1.1.1-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f9cb6d4a53aea4ddce8c4d6b5fd773d5bb1d4c7338dadc88d9737d1ced643c2 |
|
MD5 | 4e97e4af00bf9c601c1d3ef2acf9655f |
|
BLAKE2b-256 | b0b43e534cca3ae3d6cff036cc6514d224ea44f6819f487b28e10a587c84fed3 |