python中英文混合字符串对齐输出,,#!/usr/bin/e
文章由Byrx.net分享于2019-03-23 05:03:46
python中英文混合字符串对齐输出,,#!/usr/bin/e
#!/usr/bin/env python# -*- coding: utf-8 -*-def is_chinese(uchar): """判断一个unicode是否是汉字""" if uchar >= u'\u4e00' and uchar <= u'\u9fa5': return True else: return Falsedef fill_text_to_print_width(text, width): stext = str(text) utext = stext.decode("utf-8") cn_count = 0 for u in utext: if is_chinese(u): cn_count += 1 return " " * (width - cn_count - len(utext)) + stextdef print_table_line(title_config_pairs): fmt = "|".join((["{}"] * len(title_config_pairs))) print fmt.format(*map(lambda x:fill_text_to_print_width(x[0], x[1]), title_config_pairs))print_table_line(( ("标题1", 10), ("2标题1", 11), ("2标11题1", 13), ("abc", 5),))print_table_line(( ("好不好", 10), ("琰good", 11), ("琰go琰", 13), ("234", 5),))
相关内容
- ping网段设备,ping网设备,#!/usr/bin/e
- 打印目录树,打印目录,# coding=utf
- 抓取期货咨询供分析,抓取期货咨询,# encoding:u
- 对比list的处理速度,list处理速度,#网上代码def ope
- ip反查,ip,#!/usr/bin/p
- python创建桌面快捷方式的代码,python创建快捷方式,有了
- 打印斐波拉契数列,斐波数列,#打印斐波拉契数列#!/
- 用python脚本监控并发量,python脚本并发,该脚本作用用于
- python分解质因数,python质因数,from math im
- 演示类和继承,演示类继承,class Employ
评论关闭