<返回更多

python打印出八卦和六十四卦的符号和unicode编码

2023-02-08  今日头条  程序化快速交易
加入收藏

易经中的八卦和六十四卦符号,文档输入时都不是很方便,word或有些拼音输入法都可以把八卦符号当作特殊符号来输入,很少提供六十四卦符号,碰到六十四卦符号就有点麻烦了,甚至不得不绘制成相应的图形来处理,但是六十四卦符号在unicode字符集中都有,只是和八卦符号的编码不相邻。

前两天写代码时,正好也遇到六十四符号输入和输出的问题,就写了一小段Python/ target=_blank class=infotextkey>Python代码,把八卦和六十四卦符号及其unicode编码打印出来,方便查找。

代码段如下:

gua8_hanzi = ["乾","兑","离","震","巽","坎","艮","坤"]
gua64_hanzi = ["乾","坤","屯","蒙","需","讼","师","比","小畜","履","泰","否",
              "同人","大有","谦","豫","随","蛊","临","观","噬嗑","贲",
              "剥","复","无妄","大畜","颐","大过","坎","离",
              "咸","恒","遁","大壮","晋","明夷","家人","睽",
              "蹇","解","损","益","夬","姤","萃","升","困","井","革","鼎","震",
              "艮","渐","归妹","丰","旅","巽","兑","涣","节","中孚",
              "小过","既济","未济"]
print(len(gua8_hanzi),len(gua64_hanzi))

8, 64

以上语句构建八卦和六十四卦的汉字的列表,并确认个数。

symbol8 = []
symbol8_unicode = []
for i in range(2630,2638):
    expression = "u'\u"+str(i)+"'" 
    symbol8.Append(eval(expression))
    symbol8_unicode.append(str(i))

symbol64 = []  
symbol64_unicode = []
for i in range(19904,19968):
    expression = "u'\u"+str(hex(i))[2:] + "'" 
    symbol64.append(eval(expression)) 
    symbol64_unicode.append(str(i)) 

下面打印出八卦的汉字名、符号及其unicode编码,

print('八卦:')
print("t".join("".join([gua_zi,' ',gua_sign,' ',gua_unicode]) for gua_sign,gua_zi,gua_unicode in list(zip(gua8_hanzi[:4],symbol8[:4],symbol8_unicode[:4]))))
print("t".join("".join([gua_zi,' ',gua_sign,' ',gua_unicode]) for gua_sign,gua_zi,gua_unicode in list(zip(gua8_hanzi[4:],symbol8[4:],symbol8_unicode[4:]))))

输出结果如下:

八卦:
☰ 乾 2630	☱ 兑 2631	☲ 离 2632	☳ 震 2633
☴ 巽 2634	☵ 坎 2635	☶ 艮 2636	☷ 坤 2637

下面打印出六十四卦的汉字名、符号及其unicode编码,

print("六十四卦:")
for i in range(0,64,8):
    print("t".join(["".join([x,' ',y,' ',z]) for x,y,z in zip(gua64_hanzi[i:i+8],symbol64[i:i+8],symbol64_unicode[i:i*8])]))

输出结果如下:

六十四卦:
小畜 ䷈ 19912	履 ䷉ 19913	泰 ䷊ 19914	否 ䷋ 19915	同人 ䷌ 19916	大有 ䷍ 19917	谦 ䷎ 19918	豫 ䷏ 19919
随 ䷐ 19920	蛊 ䷑ 19921	临 ䷒ 19922	观 ䷓ 19923	噬嗑 ䷔ 19924	贲 ䷕ 19925	剥 ䷖ 19926	复 ䷗ 19927
无妄 ䷘ 19928	大畜 ䷙ 19929	颐 ䷚ 19930	大过 ䷛ 19931	坎 ䷜ 19932	离 ䷝ 19933	咸 ䷞ 19934	恒 ䷟ 19935
遁 ䷠ 19936	大壮 ䷡ 19937	晋 ䷢ 19938	明夷 ䷣ 19939	家人 ䷤ 19940	睽 ䷥ 19941	蹇 ䷦ 19942	解 ䷧ 19943
损 ䷨ 19944	益 ䷩ 19945	夬 ䷪ 19946	姤 ䷫ 19947	萃 ䷬ 19948	升 ䷭ 19949	困 ䷮ 19950	井 ䷯ 19951
革 ䷰ 19952	鼎 ䷱ 19953	震 ䷲ 19954	艮 ䷳ 19955	渐 ䷴ 19956	归妹 ䷵ 19957	丰 ䷶ 19958	旅 ䷷ 19959
巽 ䷸ 19960	兑 ䷹ 19961	涣 ䷺ 19962	节 ䷻ 19963	中孚 ䷼ 19964	小过 ䷽ 19965	既济 ䷾ 19966	未济 ䷿ 19967

(本文完)

 

声明:本站部分内容来自互联网,如有版权侵犯或其他问题请与我们联系,我们将立即删除或处理。
▍相关推荐
更多资讯 >>>