Skip to main content

Like webbrowser, but for the text editor.

Project description


Programmatically open the system's editor from your Python program (like webbrowser but for text editors).

Unlike other libraries, TextEditor makes an effort to find the text editor the users really prefer, specially for those that doesn't know what the EDITOR environment variable is.

Temporal file

import texteditor

text ="This is the starting content")

Opens a temporary file with some content to edit, and returns the new content when the user closes the editor.

Existing (or new) file

text ="")

# Warning: By doing the following, you will overwrite the existing content:
# text =
#   text="This will replace the file content",
#   filename=""
# )

You can also edit an existing text file or one you want to create.


Using pip of course!

python -m pip install texteditor

Usage, filename=None, extension="txt", encoding=None)

Opens filename or a new temporary file in the default editor.

  • text: The starting content for the edited file. This will also be used instead of the original contents of filename if one is also defined.

  • filename: Edit this file instead of a new temporary one.

  • extension: When editing a new temporary file, this will help the editor recognize the intended filetype, so syntax highlighting and custom settings for that filetype can be used. Examples: txt, md, ini. Ignored if filename is used.

  • encoding: To encode the content and decode the result, uses the default encoding for the platform, but you can use an encoding argument to specify any text encoding supported by Python.

How it Works first looks for the EDITOR environment variable. If set, it uses the value as-is, including any command-line argument, without fallbacks.

If no EDITOR is set, it tries to guess.

To do so, the function search through a very short list of the most popular editors, and use the first one that founds.

On MacOS, as fallback, it calls the system default for editing that file extension.

You might notice that vim and Emacs are not in the short list of editors, that's because:

  1. If you are using either of them, you know what the EDITOR variable is, and you probably has set it already.
  2. If you aren't using it, finding yourself in their UI for the first time is going to be super confusing. In fact "How to exit vim" is a common Stack Overflow question. Having to google how to set an EDITOR variable is a less scary alternative.

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

texteditor-1.4.1.tar.gz (5.3 kB view hashes)

Uploaded source

Built Distribution

texteditor-1.4.1-py3-none-any.whl (5.3 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page