a method to make some handy tools with python

In my working of computer, there are a lot of simple jobs that are frequently repeated. I tried to find a way to make these job been processed easily.

Method 1: The method is writing a script to do the job, and executing the script by utools extension utools-ScriptRunner.

Method 2: writing a script to do the job, giving the script with extension .pyy, and associating files with pyy extension to python.exe to quick lanuch the script. The reason to do these is I want to always open .py files with vscode. Then double clicking the .pyy file or searching the .pyy file in everything pressing enter on the expected item, will both trigger the script.

Example:

# csv2tiff.pyy
import re
import clipboard
import os
import cv2
import numpy as np
# clipboard.copy("abc") # now the clipboard content will be string "abc"
# text = clipboard.paste() # text will have the content of clipboard
text = clipboard.paste()
lsA = text.splitlines()
# lsB = []
# for line in lsA:
# line = re.sub(r"\\", "/", line)
# theMatch = re.search("^\"*(.*?)\"*$", line)
# # print(theMatch)
# line = f'"{theMatch.groups()[0]}"'
# lsB.append(line)
# text = "\n".join(lsB)
# clipboard.copy(text)
# print(lsA)
for idx, ff in enumerate(lsA):
print(f"idx {idx:6d} / {len(lsA)} : {ff}")
answer = input("are you sure to convert these files?\n`ctrl + C` to exit.")
for idx, ff in enumerate(lsA):
print(f"idx {idx:6d} / {len(lsA)} : {ff}")
img = np.loadtxt(ff, delimiter=",")
img = img.astype(np.float32)
cv2.imwrite(ff + ".tiff", img)
os.system("pause")

reference

wenjinghuan999/utools-ScriptRunner: utools插件,可将监视目录下的所有python脚本文件自动加入关键字列表: https://github.com/wenjinghuan999/utools-ScriptRunner

posted on   yusisc  阅读(5)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示