Open the default text editor
Project description
editor opens an editor onto an existing file, a new file, or a tempfile, lets the user edit text, and returns the results.
EXAMPLE
Using a temporary file
If no filename is provided, a temporary file gets edited, and its contents returned.
import editor
MESSAGE = 'Insert comments below this line\n\n'
comments = editor(MESSAGE)
# Pops up the default editor with a tempfile, containing MESSAGE
EXAMPLE
Using a named file
If a filename is provided, then it gets edited!
import os
FILE = 'file.txt'
assert not os.path.exists(FILE)
comments = editor(MESSAGE, filename=FILE)
# Pops up an editor for new FILE containing MESSAGE, user edits
assert os.path.exists(FILE)
# You can edit an existing file too, and select your own editor.
# By default, it uses the editor from the environment variable EDITOR
comments2 = editor(filename=FILE, editor='emacs')
API
editor.editor(text=None, filename=None, editor=None, shell=False, initial_contents=None)
Open a text editor, user edits, return results
- ARGUMENTS
- text
If not None, this string is written to the file before the editor is opened.
- filename
If not None, the name of the file to edit. If None, a temporary file is used.
- editor
The path to an editor to call. If None, use editor.default_editor() If None, use editor.default_editor().
editor can either be a string, or a list or tuple of strings. Depending on the setting of shell=, it will be converted into the right type using shlex.split or shlex.join.
- shell
Passed to subprocess.call
- initial_contents
Same as text. For backwards compatibility.
editor.default_editor()
Return the default text editor.
The default text editor is the contents of the environment variable EDITOR, it it’s non-empty, otherwise if the platform is Windows, it’s ‘notepad’, otherwise ‘vim’.
(automatically generated by doks on 2020-10-11T13:37:46.581168)
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.