okdir
Project description
okdir
安装
pip install okdir
使用
以下以我们需要建立一个物种描述文件夹为例来说明okdir的使用,该文件夹的结构为:
.
├── metadata.json // 物种元数据,包含物种名、异名、分类等
├── thumbnail.png // 物种缩略图
├── morphology.txt // 物种描述
├── synonyms.txt // 物种异名
├── taxons.txt // 物种分类信息
├── pictures // 物种图片文件夹
│ ├── lossless // 无损图片文件夹
│ └── thumbnails // 缩略图文件夹
├── sequences // 序列文件夹
├── references.txt // 参考文献
├── distributions.txt // 分布地文件
└── collections.txt // 采集地文件
定义文件夹
from okdir import File, Dir
class PicturesDir(Dir):
lossless_dir = Dir('lossless')
thumbnails_dir = Dir('thumbnails')
class SpeciesDir(Dir):
metadata_file = File('metadata.json')
thumbnail_file = File('thumbnail.png')
morphology_file = File('morphology.txt')
synonyms_file = File('synonyms.txt')
taxons_file = File('taxons.txt')
pictures_dir = PicturesDir('pictures')
sequences_dir = Dir('sequences')
references_file = File('references.txt')
distributions_file = File('distributions.txt')
collections_file = File('collections.txt')
使用文件夹
1 实例化SpeciesDir
species_dir = SpeciesDir('/Users/dev/Tests/24120901', True)
(1)第一个参数:/Users/dev/Tests/24120901代表SpeciesDir根目录
(2)第二个参数True代表将此根目录应用到其所有的子目录、子文件中
2 检查子目录、子文件是否存在
try:
species_dir.check()
except FileNotFoundError:
print('有子目录或子文件不存在')
3 创建子目录
species_dir.mkdir()
4 创建子文件
species_dir.touch()
5 获取文件夹路径
任何File、Dir的实例都有一个path属性,为一个pathlib.Path的实例:
print(species_dir.pictures_dir.lossless_dir.path)
print(species_dir.pictures_dir.lossless_dir.path / 'foo.png')
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
okdir-1.0.1.tar.gz
(3.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file okdir-1.0.1.tar.gz.
File metadata
- Download URL: okdir-1.0.1.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d6c01fc21a9bb48960814ab0e01aaa7bc1c946725dcf2d7e3bae2fd02cbc711
|
|
| MD5 |
e0016b513016ea12e21d10aed2bdcc45
|
|
| BLAKE2b-256 |
6139b7b2b1683aef68356341a6170775bf10fde4c4ab15b63061b7e3cbb07a66
|
File details
Details for the file okdir-1.0.1-py2.py3-none-any.whl.
File metadata
- Download URL: okdir-1.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 2.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16404bc777ef854c408833038338aee89fadf80aaf29003533f75e769040296b
|
|
| MD5 |
195793c7055bc5c5e950d2888c792fdd
|
|
| BLAKE2b-256 |
45550a79d9556683b565ca52fdce12b5e02b764289d719f0244906a60fcfdae2
|