Skip to main content

🖋 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 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')

Command and text handling

An editor command string retains its legacy POSIX shlex parsing. For portable paths and editor arguments, pass an argv sequence instead:

comments = editor.editor(filename=FILE, editor=['emacs', '-nw'])

The edited path is always one final argument, including when it contains spaces or quotes. encoding and errors are optional controls for reading and writing text; omit them to retain the platform-default behavior.

API Documentation

A note on AI use

Version 2.0 has exactly the same API as before, and the great majority of the code is still the handwritten code from before, but I recently used a coding assistant to find a lot of possible errors and edge cases and fix them.

I believe it should do exactly what it did before, but not fail in some unusual but certainly not impossible cases. Please let me know with an issue report if any problems crop up.

Metadata

Release files for editor 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for editor 2.0.1
File Size Uploaded
editor-2.0.1.tar.gz 29.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for editor 2.0.1
File Interpreter ABI Platform
editor-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 33.7 kB

Release files / editor-2.0.1.tar.gz

Download URL editor-2.0.1.tar.gz
Size 29.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6ecdff42bf4a32ba250f42676dbcdd75ce5fa498ca8dd1e1918c63a2518538cf
BLAKE2b-256 checksum
How to use checksums
c310d3ace6204a16ad24d9c5e330b6b09e020967d3dda3b5a6c34caa182be7b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / editor-2.0.1-py3-none-any.whl

Download URL editor-2.0.1-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
96277ffb0c529d9b54f0c10bff4bd39d23ab1298504424232319b1a26b41240a
BLAKE2b-256 checksum
How to use checksums
40fdf139b1ffdd06a06c6a2e3e542fa88963b59cb6165fd572d1220e901e288f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

1.8.0

2 release files

1.7.0

2 release files

1.6.6

2 release files

1.6.5

2 release files

1.6.4

2 release files

1.6.3

2 release files

1.6.2

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.10.1

2 release files

0.9.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page