Skip to main content

🖋 Open the default text editor 🖋

Project description

🖋 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

Project details


Download files

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

Source Distribution

editor-1.6.4.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

editor-1.6.4-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file editor-1.6.4.tar.gz.

File metadata

  • Download URL: editor-1.6.4.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.11 Darwin/21.6.0

File hashes

Hashes for editor-1.6.4.tar.gz
Algorithm Hash digest
SHA256 6aee95e0ce48069347af59443ad5b471ea6fa947e1d33697258e12ec3c280220
MD5 8f859f4c5f75c64106f8dff7335f6d4e
BLAKE2b-256 6324356d1d8944c754678f8d8398e48caf2ff8a866d1c74eee876001715518dc

See more details on using hashes here.

File details

Details for the file editor-1.6.4-py3-none-any.whl.

File metadata

  • Download URL: editor-1.6.4-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.11 Darwin/21.6.0

File hashes

Hashes for editor-1.6.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b58f1de77e1f1e78bf38c2fee755fc2ea430aaccfc4425beace4adbea64b490a
MD5 030352bb45604d288c3ac62faf3d7ef3
BLAKE2b-256 0ccb7499428099b2f19bffedd2a9e69b2c089835f724d304b040d64660089c86

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page