Proper implementation of os.startfile to launch a target file/URL
Project description
shopen
shopen is a proper implementation of os.startfile to launch a target file/URL. Use it to launch the preferred system viewer for the user to view or edit a target file or URL.
"shopen" is short for shutil.open
, the proposed builtin it's intended to be a reference implementation for.
Usage
Simply install as a dependency of your project and then use it to launch an opener for a file or URL:
import pathlib, shopen
shopen.open("https://zombo.com/") # Opens web browser
shopen.open(pathlib.Path("~/somefile.txt").expanduser()) # Opens file viewer
shopen.open(pathlib.Path("./somefile.toml"), "edit") # Opens editor
Why?
Python's standard library provides nice cross-platform utilites for lots of different purposes, but so far no simple file/URL opener that would work on all platforms.
On Windows there's os.startfile, but strangely that doesn't support any other platform.
The proposal python/cpython#47427 to implement it
as shutil.open
was rejected for now. Python users keep asking
for a decent way to do it, but the only answer had been brittle copypasta… until now!
Ideally this can be added into stdlib after proving its usefulness and then only be needed as a polyfill for older versions of python.
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
Built Distribution
File details
Details for the file shopen-0.2.2.tar.gz
.
File metadata
- Download URL: shopen-0.2.2.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e702c57616768856a86cf39cb780470196b6d96a20caa2b2703ae0334235edd |
|
MD5 | 45209a8533fedaf0192a6d35a6d5a770 |
|
BLAKE2b-256 | 3d6e3bd9e1d801fce365962f3c9c71eed6154d9d97c7f73946cbce4371d2faff |
File details
Details for the file shopen-0.2.2-py3-none-any.whl
.
File metadata
- Download URL: shopen-0.2.2-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d584291c76e64bda7f04ea168afb3314c2bfe194b5098f863d735753550ab373 |
|
MD5 | bd071f5aeb3ec9bd5113aac6ea4db689 |
|
BLAKE2b-256 | 01fd634b8d5a76af735988e28462d71056abb3e5087233b1166b453f2b522d81 |