python控制台显示时钟的示例

yipeiwu_com6年前Python基础

复制代码 代码如下:

#!/usr/bin/env python
# coding: utf-8
#
#
# show time in console
#
import sys
import time

raws = '''
.--.

|  |

`--`
  .
 /|

  |
 ---
---.

---`

`---
---.

---|

---`
.  .

`--|

   |
.---

`--.

---`
.---

|--.

`--`
.--.

`  |

   |
.--.

|--|

`--`
.--.

`--|

---`
'''.strip()
numbers = {}
def init():
    for num in range(10):
        numbers[str(num)] = []
    lineno = 0
    for line in raws.split('\n'):
        line = line.ljust(4)
        arr = []
        for char in line:
            arr.append(char) # != ' ')
        numbers[str(lineno/5)].append(arr)
        lineno += 1
    numbers[':'] = [[' ', ' ', ' ', ' '], [' ', ' ', '-', ' '], [' ', ' ', ' ', ' '], [' ', ' ', '-', ' '], [' ', ' ', ' ', ' ']]
    numbers[' '] = [[' ', ' ', ' ', ' '], [' ', ' ', ' ', ' '], [' ', ' ', ' ', ' '], [' ', ' ', ' ', ' '], [' ', ' ', ' ', ' ']]
def print_num(digtal):
    digtal = str(digtal)
    screen = []
    for i in range(5):
        screen.append([])
    for num in digtal:
        for i, linechar in enumerate(numbers[num]):
            for char in linechar:
                screen[i].append(char)
            screen[i].append('   ')
    for line in screen:
        print ''.join(line)
init()
def cls():
    sys.stdout.write('\033[2J\033[0;0H')
    sys.stdout.flush()

while True:
    t = time.strftime("%H:%M:%S")
    cls(); print_num(t)
    time.sleep(1)
    t = time.strftime("%H %M %S")
    cls(); print_num(t)
    time.sleep(1)

相关文章

Python实现的凯撒密码算法示例

Python实现的凯撒密码算法示例

本文实例讲述了Python实现的凯撒密码算法。分享给大家供大家参考,具体如下: 一 介绍 凯撒密码是一种非常古老的加密方法,相传当年凯撒大地行军打仗时为了保证自己的命令不被敌军知道,就使...

Tensorflow简单验证码识别应用

Tensorflow简单验证码识别应用

简单的Tensorflow验证码识别应用,供大家参考,具体内容如下 1.Tensorflow的安装方式简单,在此就不赘述了. 2.训练集训练集以及测试及如下(纯手工打造,所以数量不多):...

python 中Arduino串口传输数据到电脑并保存至excel表格

python 中Arduino串口传输数据到电脑并保存至excel表格

起因:学校运河杯报了个项目,制作一个天气预测的装置。我用arduino跑了BME280模块,用蓝牙模块实现两块arduino主从机透传。但是为了分析,还需要提取出数据。因此我用pytho...

Python的Flask框架中使用Flask-SQLAlchemy管理数据库的教程

Python的Flask框架中使用Flask-SQLAlchemy管理数据库的教程

使用Flask-SQLAlchemy管理数据库 Flask-SQLAlchemy是一个Flask扩展,它简化了在Flask应用程序中对SQLAlchemy的使用。SQLAlchemy是一...

Python轻量级ORM框架Peewee访问sqlite数据库的方法详解

本文实例讲述了Python轻量级ORM框架Peewee访问sqlite数据库的方法。分享给大家供大家参考,具体如下: ORM框架就是 object relation model,对象关系...