# PythonCaptureRecognition-yys **Repository Path**: MaverickMing/PythonCaptureRecognition-yys ## Basic Information - **Project Name**: PythonCaptureRecognition-yys - **Description**: 阅读FK-Onmyoji的源码学习一下实现抓图识别的功能程序 - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-04-22 - **Last Updated**: 2021-04-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## Python抓图识别 1.getTimeFormatted()函数用来获取本地时间 ~~~python def getTimeFormatted(): """ 获取本地时间 :return: 格式化后的【时间】字符串 """ the_time = time.localtime() print('time.localtime() :', the_time) # 打印结果: # time.localtime() : # time.struct_time( # tm_year=2021, tm_mon=4, tm_mday=22, # tm_hour=20, tm_min=47, tm_sec=4, # tm_wday=3, tm_yday=112, tm_isdst=0) # int tm_sec; /* 秒 – 取值区间为[0,59] */ # int tm_min; /* 分 - 取值区间为[0,59] */ # int tm_hour; /* 时 - 取值区间为[0,23] */ # int tm_mday; /* 一个月中的日期 - 取值区间为[1,31] */ # int tm_mon; /* 月份(从一月开始,0代表一月) - 取值区间为[0,11] */ # int tm_year; /* 年份,其值等于实际年份减去1900 */ # int tm_wday; /* 星期 – 取值区间为[0,6],其中0代表星期一,1代表星期二,以此类推 */ # int tm_yday; /* 从每年的1月1日开始的天数 – 取值区间为[0,365],其中0代表1月1日,1代表1月2日,以此类推 */ # int tm_isdst; /* 夏令时标识符,实行夏令时的时候,tm_isdst为正。不实行夏令时的时候,tm_isdst为0;不了解情况时,tm_isdst()为负。 return time.strftime("[%Y-%m-%d %H:%M:%S]", time.localtime()) ~~~ 2.printWithTime()自定义函数用来附带打印时间 ~~~python def printWithTime(*args, sep=' ', end='\n', file=sys.stdout, flush=False): """ 自定义的打印函数,使得打印时可以带有时间戳 :param objects: 不定长形参【元组类型】复数,表示可以一次输出多个对象。输出多个对象时,需要用 , 分隔。 :param sep: 用来间隔多个对象,默认值是一个空格。也可以自定义为其他。 :param end: 用来设定以什么结尾。默认值是换行符 \n,我们可以换成其他字符串。 :param file: 要写入的文件对象。一般不需要指定 :param flush: :return: """ # print(getTimeFormatted()+":", sep=' ', end='') # 先打印本地时间戳 # print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False) # 再打印用户需要打印的内容 print(getTimeFormatted()+" ", end='') print(*args) # 当我们在 Python 中打印对象调用 print obj 时候,事实上是调用了 sys.stdout.write(obj+'\n') # print 将你需要的内容打印到了控制台,然后追加了一个换行符“\n” # print 会调用 sys.stdout 的 write 方法 # 以下两行在事实上等价: # sys.stdout.write('hello'+'\n') == print 'hello' ~~~ 3.inputWithTimePrompt(提示文本) 自定义拓展输入函数,在输入提示字符串前,插入时间 ~~~python def inputWithTime(*args): """ 自定义拓展的输入函数,使得输入前,打印时间戳 :param prompt: 传入输入提示字符串,如“请输入:” :return: 返回组合有时间戳+提示的input函数 """ return input(getTimeFormatted() + " ", *args) ~~~ --- ## 拓展阅读 1. Python中的[print()函数用法总结](https://mp.weixin.qq.com/s?src=11×tamp=1619094106&ver=3024&signature=c8FoskopD05VVlcdL85I1DK3fPoVwQ0pYGUCdkw4Ae44Uq0Xt2M9eXZXXCOpltmYF8e*CZ97Ud1KqSNmuhfm4up7K0Grh9naUfsUYxDV4Q2LE2dMMp2nFw5390JNijod&new=1) 2. Python [time localtime()方法](https://www.runoob.com/python/att-time-localtime.html) 3. Python [日期和时间](https://www.runoob.com/python/python-date-time.html) 4.