Skip to main content

Programmatically open an editor, capture the result.

Project description

python-editor is a library that provides the editor module for programmatically interfacing with your system’s $EDITOR.

Examples

`python 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.

`python 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.

`python 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for python-editor, version 1.0.4
Filename, size File type Python version Upload date Hashes
Filename, size python_editor-1.0.4-py2.7.egg (5.0 kB) File type Egg Python version 2.7 Upload date Hashes View hashes
Filename, size python_editor-1.0.4-py2-none-any.whl (4.9 kB) File type Wheel Python version py2 Upload date Hashes View hashes
Filename, size python_editor-1.0.4-py3.5.egg (3.1 kB) File type Egg Python version 3.5 Upload date Hashes View hashes
Filename, size python_editor-1.0.4-py3-none-any.whl (4.9 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size python-editor-1.0.4.tar.gz (7.1 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page