易經中的八卦和六十四卦符號,文檔輸入時都不是很方便,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
(本文完)