API - 常用工具箱¶
A collection of useful tools. 实用工具集合。
Including batch processing, performance analysis, data analysis, etc.. 包含批处理,性能分析,数据分析等。
Available functions: - All classes and functions: 所有类和函数
get_mac_address () |
Get mac address. |
get_hostname () |
Get hostname. |
get_ip_address (hostname) |
Get ip address. |
get_current_function_name () |
Get current function name. |
Walk () |
Walk directory to batch processing. |
time_me ([info, format_string]) |
Performance analysis - time |
get_current_time ([format_string, info]) |
Get current time with specific format_string. |
random_item (mylist) |
Get random item of data. |
file_replace (source_file, destination_file) |
File replace. |
read_excel (filepath) |
Get excel source |
set_excel_style (name, height[, bold]) |
Set excel style. |
write_excel ([filename, sheets]) |
Write excel from data. |
generate_dict (dictpath, sourcepath) |
Generate dictionary file from sourcefile. |
waitting () |
Print waitting. |
遍历目录进行批处理¶
-
chat.mytools.
Walk
()[source]¶ Walk directory to batch processing. 遍历目录进行批处理。
Subclasses may override the ‘handle_file’ method to provide custom file processing mode. 子类可以重写’handle_file’方法来实现自定义的文件处理方式。
Public attributes: - filelist: All filenames with full path in directory. - fnamelist: All filenames in directory. - dirlist: All dirnames with full path in directory. - dnamelist: All dirnames in directory.
程序时间性能分析¶
-
chat.mytools.
time_me
(info='used', format_string='ms')[source]¶ Performance analysis - time
Decorator of time performance analysis. 性能分析——计时统计 系统时间(wall clock time, elapsed time)是指一段程序从运行到终止,系统时钟走过的时间。 一般系统时间都是要大于CPU时间的。通常可以由系统提供,在C++/Windows中,可以由<time.h>提供。 注意得到的时间精度是和系统有关系的。 1.time.clock()以浮点数计算的秒数返回当前的CPU时间。用来衡量不同程序的耗时,比time.time()更有用。 time.clock()在不同的系统上含义不同。在UNIX系统上,它返回的是”进程时间”,它是用秒表示的浮点数(时间戳)。 而在WINDOWS中,第一次调用,返回的是进程运行的实际时间。而第二次之后的调用是自第一次 调用以后到现在的运行时间。(实际上是以WIN32上QueryPerformanceCounter()为基础,它比毫秒表示更为精确) 2.time.perf_counter()能够提供给定平台上精度最高的计时器。计算的仍然是系统时间, 这会受到许多不同因素的影响,例如机器当前负载。 3.time.process_time()提供进程时间。
- Args:
info: Customize print info. 自定义提示信息。 format_string: Specifies the timing unit. 指定计时单位,例如’s’: 秒,’ms’: 毫秒。
Defaults to ‘s’.