API - 常用工具箱

../_images/mytools.ico

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.

获取Mac地址

chat.mytools.get_mac_address()[source]

Get mac address.

获取主机名

chat.mytools.get_hostname()[source]

Get hostname.

获取IP地址

chat.mytools.get_ip_address(hostname)[source]

Get ip address.

获取当前运行函数名

chat.mytools.get_current_function_name()[source]

Get current function name.

遍历目录进行批处理

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’.

获取当前时间

chat.mytools.get_current_time(format_string='%Y-%m-%d-%H-%M-%S', info=None)[source]

Get current time with specific format_string. 获取指定日期表示方式的当前时间。

Args:
format_string: Specifies the format of time. 指定日期表示方式。
Defaults to ‘%Y-%m-%d-%H-%M-%S’.

列表随机元素

chat.mytools.random_item(mylist)[source]

Get random item of data. 从数据中获取随机元素。

Returns:
item: Random item of data. 数据随机项。

文件替换

chat.mytools.file_replace(source_file, destination_file)[source]

File replace. 文件替换。

Args:
source_file: The full path of source file. 原始文件完整路径。 destination_file:The full path of destination file. 目标文件完整路径。

读取excel

chat.mytools.read_excel(filepath)[source]

Get excel source

Args:
filepath: The full path of excel file. excel文件完整路径。
Returns:
data: Data of excel. excel数据。

设置excel样式

chat.mytools.set_excel_style(name, height, bold=False)[source]

Set excel style.

写入excel

chat.mytools.write_excel(filename='demo.xlsx', sheets=None)[source]

Write excel from data.

生成词典

chat.mytools.generate_dict(dictpath, sourcepath)[source]

Generate dictionary file from sourcefile.

Args:
dictpath: The full path of dict file. 源文件完整路径。 sourcepath: The full path of source file. 源文件完整路径。

显示等待中

chat.mytools.waitting()[source]

Print waitting.