首页 > 编程语言 >使用python语言实现获取当前时间,按照电子表样式打印到控制台

使用python语言实现获取当前时间,按照电子表样式打印到控制台

时间:2024-11-16 22:00:57浏览次数:1  
标签:02 03 电子表 clock python 05 result 控制台 line

使用python语言实现获取当前时间,按照电子表样式打印到控制台

clock.py

  1 from datetime import datetime
  2 
  3 # 数字0
  4 zero_line_01 = '  ---  '
  5 zero_line_02 = ' |   | '
  6 zero_line_03 = ' |   | '
  7 zero_line_04 = ' |   | '
  8 zero_line_05 = '  ___  '
  9 
 10 # 数字1
 11 one_line_01 = '   |   '
 12 one_line_02 = '   |   '
 13 one_line_03 = '   |   '
 14 one_line_04 = '   |   '
 15 one_line_05 = '   |   '
 16 
 17 # 数字2
 18 two_line_01 = '  ---  '
 19 two_line_02 = '     | '
 20 two_line_03 = '  ---  '
 21 two_line_04 = ' |     '
 22 two_line_05 = '  ---  '
 23 
 24 # 数字3
 25 three_line_01 = '  ---  '
 26 three_line_02 = '     | '
 27 three_line_03 = '  ---  '
 28 three_line_04 = '     | '
 29 three_line_05 = '  ---  '
 30 
 31 # 数字4
 32 four_line_01 = ' |   | '
 33 four_line_02 = ' |   | '
 34 four_line_03 = '  ---  '
 35 four_line_04 = '     | '
 36 four_line_05 = '     | '
 37 
 38 # 数字5
 39 five_line_01 = '  ---  '
 40 five_line_02 = ' |     '
 41 five_line_03 = '  ---  '
 42 five_line_04 = '     | '
 43 five_line_05 = '  ---  '
 44 
 45 # 数字6
 46 six_line_01 = '  ---  '
 47 six_line_02 = ' |     '
 48 six_line_03 = '  ---  '
 49 six_line_04 = ' |   | '
 50 six_line_05 = '  ---  '
 51 
 52 # 数字7
 53 seven_line_01 = '  ---  '
 54 seven_line_02 = '     | '
 55 seven_line_03 = '     | '
 56 seven_line_04 = '     | '
 57 seven_line_05 = '     | '
 58 
 59 # 数字8
 60 eight_line_01 = '  ---  '
 61 eight_line_02 = ' |   | '
 62 eight_line_03 = '  ---  '
 63 eight_line_04 = ' |   | '
 64 eight_line_05 = '  ---  '
 65 
 66 # 数字9
 67 nine_line_01 = '  ---  '
 68 nine_line_02 = ' |   | '
 69 nine_line_03 = '  ---  '
 70 nine_line_04 = '     | '
 71 nine_line_05 = '  ---  '
 72 
 73 # 分隔符
 74 separator_line_01 = '       '
 75 separator_line_02 = '   .   '
 76 separator_line_03 = '       '
 77 separator_line_04 = '   .   '
 78 separator_line_05 = '       '
 79 
 80 # 分隔符
 81 empty_line_01 = '       '
 82 empty_line_02 = '       '
 83 empty_line_03 = '       '
 84 empty_line_04 = '       '
 85 empty_line_05 = '       '
 86 
 87 # 获取当前时间字符串
 88 def get_current_time_str():
 89     return datetime.now().strftime('%Y-%m-%d %H:%M:%S')
 90 
 91 # 根据字符串返返回电子表格式内容
 92 def generate_content_by_datetime_str(datetime_str):
 93     result = {
 94         'result_line_01' : '',
 95         'result_line_02' : '',
 96         'result_line_03' : '',
 97         'result_line_04' : '',
 98         'result_line_05' : ''
 99     }
100     char_list = list(datetime_str)
101     for char in char_list:
102         clock_result = generate_clock(char)
103         result['result_line_01'] += clock_result['clock_result_01']
104         result['result_line_02'] += clock_result['clock_result_02']
105         result['result_line_03'] += clock_result['clock_result_03']
106         result['result_line_04'] += clock_result['clock_result_04']
107         result['result_line_05'] += clock_result['clock_result_05']
108     return result
109 
110 # 根据当前时间返回电子表格式内容
111 def generate_content():
112     datetime_str = get_current_time_str()
113     result = generate_content_by_datetime_str(datetime_str)
114     return result
115 
116 def generate_clock(str):
117     clock_result = {'clock_result_01' : '',
118                     'clock_result_02' : '',
119                     'clock_result_03' : '',
120                     'clock_result_04' : '',
121                     'clock_result_05' : ''}
122     if '0' == str:
123         clock_result['clock_result_01'] = zero_line_01
124         clock_result['clock_result_02'] = zero_line_02
125         clock_result['clock_result_03'] = zero_line_03
126         clock_result['clock_result_04'] = zero_line_04
127         clock_result['clock_result_05'] = zero_line_05
128     if '1' == str:
129         clock_result['clock_result_01'] = one_line_01
130         clock_result['clock_result_02'] = one_line_02
131         clock_result['clock_result_03'] = one_line_03
132         clock_result['clock_result_04'] = one_line_04
133         clock_result['clock_result_05'] = one_line_05
134     if '2' == str:
135         clock_result['clock_result_01'] = two_line_01
136         clock_result['clock_result_02'] = two_line_02
137         clock_result['clock_result_03'] = two_line_03
138         clock_result['clock_result_04'] = two_line_04
139         clock_result['clock_result_05'] = two_line_05
140     if '3' == str:
141         clock_result['clock_result_01'] = three_line_01
142         clock_result['clock_result_02'] = three_line_02
143         clock_result['clock_result_03'] = three_line_03
144         clock_result['clock_result_04'] = three_line_04
145         clock_result['clock_result_05'] = three_line_05
146     if '4' == str:
147         clock_result['clock_result_01'] = four_line_01
148         clock_result['clock_result_02'] = four_line_02
149         clock_result['clock_result_03'] = four_line_03
150         clock_result['clock_result_04'] = four_line_04
151         clock_result['clock_result_05'] = four_line_05
152     if '5' == str:
153         clock_result['clock_result_01'] = five_line_01
154         clock_result['clock_result_02'] = five_line_02
155         clock_result['clock_result_03'] = five_line_03
156         clock_result['clock_result_04'] = five_line_04
157         clock_result['clock_result_05'] = five_line_05
158     if '6' == str:
159         clock_result['clock_result_01'] = six_line_01
160         clock_result['clock_result_02'] = six_line_02
161         clock_result['clock_result_03'] = six_line_03
162         clock_result['clock_result_04'] = six_line_04
163         clock_result['clock_result_05'] = six_line_05
164     if '7' == str:
165         clock_result['clock_result_01'] = seven_line_01
166         clock_result['clock_result_02'] = seven_line_02
167         clock_result['clock_result_03'] = seven_line_03
168         clock_result['clock_result_04'] = seven_line_04
169         clock_result['clock_result_05'] = seven_line_05
170     if '8' == str:
171         clock_result['clock_result_01'] = eight_line_01
172         clock_result['clock_result_02'] = eight_line_02
173         clock_result['clock_result_03'] = eight_line_03
174         clock_result['clock_result_04'] = eight_line_04
175         clock_result['clock_result_05'] = eight_line_05
176     if '9' == str:
177         clock_result['clock_result_01'] = nine_line_01
178         clock_result['clock_result_02'] = nine_line_02
179         clock_result['clock_result_03'] = nine_line_03
180         clock_result['clock_result_04'] = nine_line_04
181         clock_result['clock_result_05'] = nine_line_05
182     if ':' == str:
183         clock_result['clock_result_01'] = separator_line_01
184         clock_result['clock_result_02'] = separator_line_02
185         clock_result['clock_result_03'] = separator_line_03
186         clock_result['clock_result_04'] = separator_line_04
187         clock_result['clock_result_05'] = separator_line_05
188     if ' ' == str:
189         clock_result['clock_result_01'] = empty_line_01
190         clock_result['clock_result_02'] = empty_line_02
191         clock_result['clock_result_03'] = empty_line_03
192         clock_result['clock_result_04'] = empty_line_04
193         clock_result['clock_result_05'] = empty_line_05
194     return clock_result

 

test.py

 1 import clock
 2 
 3 # 测试时钟方法
 4 # clock_result = clock.generate_content_by_datetime_str('1997-05-29 00:00:00')
 5 # print(clock_result['result_line_01'])
 6 # print(clock_result['result_line_02'])
 7 # print(clock_result['result_line_03'])
 8 # print(clock_result['result_line_04'])
 9 # print(clock_result['result_line_05'])
10 
11 while True:
12     clock_result = clock.generate_content()
13     print(clock_result['result_line_01'])
14     print(clock_result['result_line_02'])
15     print(clock_result['result_line_03'])
16     print(clock_result['result_line_04'])
17     print(clock_result['result_line_05'])
18     print("")
19     time.sleep(1)

 

标签:02,03,电子表,clock,python,05,result,控制台,line
From: https://www.cnblogs.com/mxh-java/p/18549876

相关文章

  • 【动手做】Python实现线性回归
    线性回归是机器学习中形式比较简单的模型,能够很好的进行推导和求解,也便于图形化展示。关于线性回归的概念和表示,在线性回归的概念与表示有比较详细的的介绍。本文通过手动实现、调用scikit-learn类库两种方式演示了线性回归模型,并通过matplotlib进行了可视化展示。实现过程本......
  • python实现十进制转换二进制,tkinter界面
    目录需求效果代码实现代码解释需求python实现十进制转换二进制效果代码实现importtkinterastkfromtkinterimportmessageboxdefconvert_to_binary():try:#获取输入框中的十进制数decimal_number=int(entry.get())#转......
  • Python 语法基础:赋值、深浅拷贝、可变与不可变对象
    Python是一种广泛使用的高级编程语言,其语法简洁且功能强大。本文将详细讲解Python中的赋值、深浅拷贝以及可变与不可变对象的基本概念和使用方法。一、赋值赋值是编程中最基本的操作之一,它用于将值或对象绑定到变量名。在Python中,赋值使用等号=来进行。a=10......
  • python文件排序都有哪些方法
    在python环境中提供两种排序方案:用库函数sorted()对字符串排序,它的对象是字符;用函数sort()对数字排序,它的对象是数字,如果读取文件的话,需要进行处理(把文件后缀名‘屏蔽’)。(1)首先:我测试的文件夹是/img/,里面的文件都是图片,如下图所示:(2)测试库函数sorted(),直接贴出代码:impor......
  • 使用Python实现智能食品安全监测的深度学习模型
    食品安全是关乎公共健康的重要议题。随着科技的发展,深度学习技术在食品安全监测中的应用越来越广泛,通过自动化和智能化手段,可以有效提高食品质量检测的效率和准确性。本文将介绍如何使用Python实现一个智能食品安全监测的深度学习模型,并通过代码示例展示实现过程。项目概述......
  • Python基础:探索迭代器(Iterator)的奥秘
    引言在当今的科技时代,Python作为一种功能强大且广泛应用的编程语言,在数据处理、人工智能、网络爬虫等诸多领域发挥着不可替代的作用。迭代器作为Python中的一个重要概念,对于高效处理数据、优化算法等有着极大的意义。它能够以一种简洁而有效的方式遍历数据结构,无论是大型数......
  • 【Python】基础语法速览(上)
    本文力图用最快的方式向大家陈列Python的基础语法,适合接触过其他编程语言后快速上手Python或供查阅巩固用参考书籍:《Python程序设计人工智能案例实践》[美]保罗·戴特尔哈维·戴特尔著码字不易,求点赞收藏加关注有问题欢迎评论区讨论目录Python基础语法速览(上)变......
  • Python实现Graham Scan算法并进行凸包计算
    目录使用GrahamScan算法进行凸包计算第一部分:GrahamScan算法概述1.1什么是GrahamScan算法?1.2算法的应用场景1.3算法的优点和局限第二部分:算法的数学基础与步骤2.1凸包的定义与性质2.2算法的关键步骤2.3极角计算公式2.4算法流程图第三部分......
  • Jarvis March算法详解及Python实现(附设计模式案例)
    目录JarvisMarch算法详解及Python实现(附设计模式案例)第一部分:JarvisMarch算法概述与原理1.1什么是JarvisMarch算法?1.2算法原理1.3算法流程1.4时间复杂度第二部分:JarvisMarch算法的Python实现(面向对象设计)2.1面向对象设计2.2代码实现2.3代......
  • 如何使用python批量读取母文件夹下的子文件夹名称
    文件准备如上图所示,我想要将dir中的所有的子文件夹的文件名打印出来代码准备importoscutrrent_dictionary=os.getcwd()#该值所代表的含义就是打开文件的绝对路径cutrrent_dictionary="D:\400-File\000-Project\000-Pycharm\005-CSDN_File"print(cutrrent_dic......