A useful functions library for everyone.
Project description
Windlib
有用的函数库,由SNWCreations创建。
只是为个人使用而编写,但我希望这能帮助到你。
用法
typeof
typeof(variate) -> str
检测变量类型,返回字符串。
示例:
>>> a = 10
>>> typeof(a)
'int'
extract
extract(filename: str, target_dir: str) -> str
支持 ".zip" ".gz" ".tar" ".rar" ".tar.gz" 文件。
如果需要支持rar文件,则需要 "rarfile" 库。
您可以从 https://sourceforge.net/projects/rarfile.berlios/files/latest/download 下载 rarfile 库。
示例:
>>> extract('a.zip', 'a')
'OK'
>>>
get_file
get_file(url: str, save_path: str) -> str
从互联网下载文件,并附带一个进度条。
参数:
url: 被下载文件的URL
save_path: 保存路径,默认为当前路径
timeout: 超时时长,单位为秒,默认为 10
返回: 下载后的文件名,下载失败返回'DOWNLOAD_FAILED'
find_files_with_the_specified_extension
find_files_with_the_specified_extension(file_type: str, folder: str, slient: bool) -> list
在目标文件夹中找到具有指定扩展名的文件,返回值是一个列表。
参数:
folder: 从哪里查找,默认值为当前目录。
file_type: 一个扩展名,不需要带有 “.” 。例如 "txt", "jar", "md", "class" 或 ".txt" ".jar" ".md" ".class".
返回: 被筛选的文件名的列表
copy_file
copy_file(src: str or list or tuple, dst: str) -> None
复制文件(或文件夹)到指定的目录。
可以通过列表的方式同时将多个文件复制到指定目录。
参数:
src: 源文件或目录
dst: 目标路径
is_it_broken
is_it_broken(path: str or list) -> bool or list
检查一个文件(或目录)是否损坏。
允许调用时通过列表检查大量文件和目录。
若使用列表来检查文件,则返回一个记录所有损坏的文件路径的列表。
参数:
path: 文件路径
示例:
>>> is_it_broken('./aaa.txt')
False
>>> is_it_broken(['./aaa.txt', './bbb.txt', './ccc.txt'])
[]
pushd
pushd(new_dir: str)
临时切换到一个目录,操作完成后自动返回调用前路径。
此函数为生成器,请配合 with 语句使用。
参数:
new_dir: 路径
示例:
>>> print(os.getcwd())
'D:\\windlib-test'
>>> with pushd('./aaa'):
... print(os.getcwd())
'D:\\windlib-test\\aaa'
>>> print(os.getcwd())
'D:\\windlib-test'
compress
compress(input_path: str, output_name: str, output_path: str = '.', ext='zip') -> str
压缩一个目录下的所有文件到一个zip文件,无返回值。
参数:
input_path: 压缩的文件夹路径
output_name: 压缩包名称 (不需要带扩展名)
output_path: 输出的路径
ext: 压缩包类型 (有效值: 'zip', 'tar', 'tar.gz')
返回: 压缩包文件的完整路径
示例:
>>> compress('./a', 'a', ext='zip')
'D:\windlib-test\a.zip'
>>>
get_sha1
get_sha1(path: str) -> str
获取一个文件的SHA1校验值,返回值是一个字符串。
参数:
path: 文件路径
示例:
>>> get_sha1('setup.py')
'acdf35508f4dfb49e522f161a3e3e885adbf3b99'
get_md5
获取一个文件的MD5校验值,返回值是一个字符串。
参数:
path: 文件路径
示例:
>>> get_md5('setup.py')
'ec210fa5cc05bed851da3fe222b733a9'
版权所有 (C) 2021 SNWCreations。
欢迎对此库做出 Commit 和 Pull Request!
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
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 windlib-1.8.0.tar.gz.
File metadata
- Download URL: windlib-1.8.0.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9a492d107e17fb5930e293359131fa5fef41c4509166fb4c00e384236494e23
|
|
| MD5 |
1198b78f82de6f65401bf495f8dbd957
|
|
| BLAKE2b-256 |
8886896ffc4c7f5018537bd96c43b5955f689b895bf93c91096f6e323486dba5
|
File details
Details for the file windlib-1.8.0-py3-none-any.whl.
File metadata
- Download URL: windlib-1.8.0-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02c8be0cf0ae5c43cb02b7a651160497b18b9b7e7ff95fc89e9da92907250c44
|
|
| MD5 |
758fbeabf01cadf946dfb7166803d9a1
|
|
| BLAKE2b-256 |
2623f70b408b0716558c06f71c287784941893a189d25557f5804554460cbca0
|