当前位置: 主页 > 888真人手机版 > 正文

Python何以完成太阳历转太阴历的方法分享

作者:admin 来源:未知 浏览: 【 】 发布时间:2018-08-27 评论数:

  pip里拥有壹个sxtwl的库。很便宜的

  pip install sxtwl 就能装置了。

  下面是替换的例儿子

  #-*-coding:utf-8-*-

  import sxtwl

  #日历华语索伸

  ymc = [u"什壹", u"什二", u"正", u"二", u"叁", u"四", u"五", u"六", u"七", u"八", u"九", u"什" ]

  rmc = [u"朔", u"初二", u"初叁", u"初四", u"初五", u"初六", u"初七", u"初八", u"初九", u"初什",

  u"什壹", u"什二", u"什叁", u"什四", u"什五", u"什六", u"什七", u"什八", u"什九",

  u"二什", u"廿壹", u"廿二", u"廿叁", u"廿四", u"廿五", u"廿六", u"廿七", u"廿八", u"廿九", u"叁什", u"卅壹"]

  lunar = sxtwl.Lunar() #实例募化日历库

  #太阴历转太阳历,如需寻求计算公元前的,用正数体即兴,譬如-20体即兴公元前20年

  day = lunar.getDayByLunar(2030, 3, 27 , False)

  print u"正太阳历:", day.y, u"年", day.m, u"月", day.d, u"日"

  if day.Lleap:

  print u"太阴历:润", ymc[day.Lmc], u"月", rmc[day.Ldi], u"日"

  else:

  print u"太阴历:", ymc[day.Lmc], u"月", rmc[day.Ldi], u"日"

  #同理,太阳历转太阴历

  day = lunar.getDayBySolar(2018, 10, 20)

  print u"正太阳历:", day.y, u"年", day.m, u"月", day.d, u"日"

  if day.Lleap:

  print u"太阴历:润", ymc[day.Lmc], u"月", rmc[day.Ldi], u"日"

  else:

  print u"太阴历:", ymc[day.Lmc], u"月", rmc[day.Ldi], u"日"

  #试壹下公元前

  day = lunar.getDayBySolar(-100, 10, 20)

  print u"正太阳历:", day.y, u"年", day.m, u"月", day.d, u"日"

  if day.Lleap:

  print u"太阴历:润", ymc[day.Lmc], u"月", rmc[day.Ldi], u"日"

  else:

  print u"太阴历:", ymc[day.Lmc], u"月", rmc[day.Ldi], u"日"

  1. 假设你想看怎么完成,你却以去看xmltodict此雕刻个第叁方库,

  2. 假设你想直接运用,亦去看xnltodict此雕刻个库,

  3. 尽的到来说,坚硬是你却以用xmltodict完成,先替换成python规范的dict,又用python己带的json.dumps()替换即却

  文字到来源:https://zhidao.baidu.com/question/1994182741812339187.html