A convenience function that delegates to the appropriate standard library function.
Project description
openfile is a trivial Python module that implements a single convenience function openfile(filename, mode="rt", **kwargs) wich delegates the real work to one of the following standard library functions:
gzip.open(filename, mode, **kwargs) if the file ends with suffix .gz;
bz2.open(filename, mode, **kwargs) if the file ends with suffix .bz2;
lzma.open(filename, mode, **kwargs) if the file ends with suffix .xz or .lzma;
open(filename, mode, **kwargs) if the file does not end with any suffix mentioned above.
If the filename is a single dash - then sys.stdin or sys.stdout is returned, depending on mode being r or w, respectively.
The following keyword arguments are used by openfile:
expanduser=True will cause openfile to call os.path.expanduser for filename.
expandvars=True will cause openfile to call os.path.expandvars for filename.
makedirs=True will cause openfile to call os.makedirs for the parent directory os.path.dirname(filename) if it does not exist and mode contains either "w" or "a".
All other keyword arguments passed to openfile will be passed down to the open functions listed above.
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 openfile-0.0.7.tar.gz
.
File metadata
- Download URL: openfile-0.0.7.tar.gz
- Upload date:
- Size: 2.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.23.2 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea4e8f19112049f578ec161b12f70c1113144988c0a488ab173a138b50f37479 |
|
MD5 | e2877c3c4ea6445f11f273d7251c3287 |
|
BLAKE2b-256 | 16466c8b936e55ace50a6d9ea722dd4b11a4996d58cff41690636a0d6f6f6718 |
File details
Details for the file openfile-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: openfile-0.0.7-py3-none-any.whl
- Upload date:
- Size: 2.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.23.2 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d21b69dba1306c9dd397a44fd8f4fa8a83812f1d935c409085e8a25c411d16ec |
|
MD5 | 3dce20af8ea5f37e80a5ba2b73f97e34 |
|
BLAKE2b-256 | 93e6805db6867faacb488b44ba8e0829ef4de151dd0499f3c5da5f4ad11698a7 |