Class with file-like interface to a file found in provided search path
Project description
Class with file-like interface to a file found in provided search path
Features
Search a path for a file that matches a pattern
Search a path for a file inside directories that match a pattern
- Basic file-like interfaces:
DisFile(…).open()
with DisFile(…) as f: …
Get path from config file (if optini module installed)
Examples
Simple usage:
from disambigufile import DisFile
path = '/bin:/usr/bin:/usr/local/bin'
try:
print(DisFile('^ls', path=path))
except Exception as e:
print(f"unable to disambiguate file; exception: {e}")
Using a with statement to open the disambiguated file:
from disambigufile import DisFile
path = 'path1:path2'
try:
with DisFile(r'^asdf', path=path) as f:
print(f.read())
except Exception as e:
print(f"unable to disambiguate file; exception: {e}")
With more specific exception handling:
from disambigufile import DisFile
import disambigufile
path = '/bin:/usr/bin:/usr/local/bin'
try:
print(DisFile('^ls', path=path))
except disambigufile.Error as e:
# will only catch module-specific exceptions
print(f"unable to disambiguate file; exception: {e}")
Match a file inside of a matched directory:
from disambigufile import DisFile
# search for unique file matching ~/Datasets/*2019-08-19*/data*
path='~/Datasets'
try:
hit = DisFile(
pattern='2019-08-19',
path=path,
subpattern='^data',
)
print(hit)
except disambigufile.Error as e:
print(f"unable to disambiguate file; exception: {e}")
License
Free software: MIT license
Documentation
Credits
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
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.
Source Distribution
Built Distribution
File details
Details for the file disambigufile-0.3.2.tar.gz
.
File metadata
- Download URL: disambigufile-0.3.2.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.25.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5349ef03829af4bf6019e400d8d954527d6be89df0e9fb54390a950cb99789c7 |
|
MD5 | 6d3de0439dabd66177ec6fd38c3bfc6e |
|
BLAKE2b-256 | 15778e7165f87c2491343cf06263cd7f8eff17f83e9458fb00d1a4b77c4cf483 |
File details
Details for the file disambigufile-0.3.2-py3-none-any.whl
.
File metadata
- Download URL: disambigufile-0.3.2-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.25.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33b541d569a493610ff62cdede1583f2feca2418aa28636e9ba28b40357d2aad |
|
MD5 | 628a7b83a117a426e713d4fa3dac8a47 |
|
BLAKE2b-256 | 04e14e5486de7b03b58019aaea00150f147f76a6697f1464a4150068ac8a11d3 |