Skip to main content

naotool

✨ 🍬A packge of utils or tools keeps Python sweet. 让 py 保持甜甜的 ✨

license:MIT pypi Python

naotool

🍬A packge of utils or tools keeps Python sweet.

快速上手

pip install naotool

最佳实践

import naotool as nt

@nt.decodeco  # 使用根模块:用 `nt.` 直接调用
@nt.deco.compat_arg_error  # 使用子模块:提高代码可读性;便于 IDE 提供更精确的语法提示
def f():
    pass
f(1, 2, 3, a=1)
print("ok!")
# 脚本任务: 修改 `.jpg` 图片的文件名为 `{md5}.jpg`
import asyncio
import os
from pathlib import Path
from PIL import Image
import naotool as nt

Image.MAX_IMAGE_PIXELS = None
img_dir = Path(r"../../imgs/")
img_name_list = filter(lambda x: x.endswith(".jpg"), os.listdir(str(img_dir)))
path_list = [img_dir / name for name in img_name_list]

async def rename_image(src: Path):
    try:
        md5 = nt.img_md5hex(await get_imgs(str(src)))
        new_path = img_dir / f"{md5}{src.suffix}"
        os.rename(src, new_path)
    except Exception as e:
        print(f"Failed to process {src}: {e}")
async def main():
    await asyncio.gather(*(rename_image(src) for src in path_list))
asyncio.run(main())

tools

module example description
cls copy_attr(a, b) SpringBean (?)
deco @decodeco() 装饰装饰器?
httpn AutoCloseAsyncClient(auto_close_time=3) 更简洁的 http
img get_imgs(["http://img.png"]) 图片
strs tight("delete b l a n k char") 你的字符串有点松弛
x get_xposts() 获取 x.com 的 文章
exception NOException 没有异常

python 设计哲学

  • 需求至上原则 - demand is God
  • 最小重复原则 - DRY 准则 - don't repeat yourself
  • 向后兼容原则 - the latest version, for the oldest code
  • 数学哲学美学 - Mathematical Philosophy Aesthetics
>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
>>>
Python 之禅(作者 Tim Peters)

美优于丑
明确的而不是隐晦的
简单的而不是复杂的
复杂的而不是繁杂的
扁平的而不是嵌套的
稀疏的而不是密集的
可读性至关重要
特例也不能破坏规则
即使假借实用性之名
不应让异常悄悄溜走
除非明确容忍错误
当面临不确定性,不要尝试去猜测
应当只有一种 —— 最好是唯一一种 —— 明显的解决方案
虽然这一开始可能并不容易,除非你是 Dutch
做也许好过不做
但不假思索就动手还不如不做
如果实现是难以解释的,那可能不是个好主意
如果实现是容易解释的,那可能是个好主意
命名空间是一种绝妙的理念 —— 我们要多加利用!

Metadata

Release files for naotool 0.3.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for naotool 0.3.5
File Size Uploaded
naotool-0.3.5.tar.gz 18.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for naotool 0.3.5
File Interpreter ABI Platform
naotool-0.3.5-py3-none-any.whl Python 3 none any Details

Total release size: 44.9 kB

Release files / naotool-0.3.5.tar.gz

Download URL naotool-0.3.5.tar.gz
Size 18.6 kB
Tags Source
SHA-256 checksum
How to use checksums
73d4732327b74efd1a1d422ffa406c74082141b0abbc393ef3188fb3c2386f8b
BLAKE2b-256 checksum
How to use checksums
4faa19f63cf63925b263f969aedaf4a29d0c5968da8171157c4a17d4b726cfe5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release files / naotool-0.3.5-py3-none-any.whl

Download URL naotool-0.3.5-py3-none-any.whl
Size 26.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b4d0e54d750aa0877e6e3af78a99a02c6aa6cb83f90112113bc1fd7dfd0ebdca
BLAKE2b-256 checksum
How to use checksums
479e63244f706232242cc92998b3b1d0cb1e725325c25073cdfa243c16dd1cfd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release history Release notifications | RSS feed

This release

0.3.5 This release

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page