A set of tools that keep Python sweeter.
Project description
SmarTool - Smart Util Tool for Python
简介
SmarTool是一个小而全的Python工具类库,类似Java的Hutool。
安装
pip install SmarTool
使用
1. Retry - 重试工具
import random
import requests
from SmarTool import retry
# 默认重试5次,每次间隔2秒,所有异常都重试
@retry
def div1(a, b):
return a / random.choice([0, 1, b])
div1(2, 1)
# 重试10次,每次间隔1秒,仅在出现ZeroDivisionError时重试
@retry(times=10, delay=1, catch_error=ZeroDivisionError)
def div2(a, b):
return a / random.choice([0, 1, b])
div2(2, 1)
# 在出现TypeError时不重试直接抛出异常
@retry(ignore_error=TypeError)
def div3(a, b):
return a / random.choice([0, 1, b])
div3(2)
# 出现指定的多个异常时重试
@retry(catch_error=[requests.exceptions.ConnectionError, requests.exceptions.ConnectTimeout])
def get():
return requests.get("https://xxx.com").json()
get()
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
SmarTool-1.0.4.tar.gz
(8.5 kB
view details)
Built Distribution
File details
Details for the file SmarTool-1.0.4.tar.gz
.
File metadata
- Download URL: SmarTool-1.0.4.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08c97c30ad706b87ab742bb85d808c0dd49006f1e8a04b3ec57273ed768d785d |
|
MD5 | 5aa123dfed7ee2dfb71c185c5599cf02 |
|
BLAKE2b-256 | 87cb58021c6dc54827ea263129db2891e5d1931b3e371c6f25d7093265a9c22a |
File details
Details for the file SmarTool-1.0.4-py3-none-any.whl
.
File metadata
- Download URL: SmarTool-1.0.4-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 735114bd7456072d367b02dda316a88368e0728ca7822722190b740f0d538747 |
|
MD5 | c02353250b4c17888d377d312ea119b8 |
|
BLAKE2b-256 | e4230d712439d1b551daae12f069bee3f050d266d3bc596e1a42001529bef570 |