#!/usr/bin/env python
# coding: utf-8
#
#
# show time in console
#
import sys
import timeraws = '''
.--.| |`--`
.
/| |
---
---.---``---
---.---|---`
. .`--| |
.---`--.---`
.---|--.`--`
.--.` | |
.--.|--|`--`
.--.`--|---`
'''.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控制台显示时钟的示例到此结束。天空收容每一片云彩,不论其美丑,所以天空宽阔无边。大地拥抱每一寸土地,不论其贫富,所以大地广袤无垠。海洋接纳每一条河流,不论其大小,所以海洋广阔无边。谢谢大家支持!