网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
11月22日漏签0天
python吧 关注:479,559贴子:1,980,635
  • 看贴

  • 图片

  • 吧主推荐

  • 视频

  • 游戏

  • 5回复贴,共1页
<<返回python吧
>0< 加载中...

求求求求求求求这段代码的<注释>_____________________________

  • 只看楼主
  • 收藏

  • 回复
  • v﹑1cc_﹨
  • 白丁
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼




  • v﹑1cc_﹨
  • 白丁
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

刚接触python 刚看到这段日历代码 但不是很明白
希望有详细注释
谢谢


2025-11-22 00:48:02
广告
不感兴趣
开通SVIP免广告
  • v﹑1cc_﹨
  • 白丁
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

被审核了、


  • v﹑1cc_﹨
  • 白丁
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
          十一 十二 十三 十四 十五 十六 十七 十八 十九 廿十\
          廿一 廿二 廿三 廿四 廿五 廿六 廿七 廿八 廿九 三十'.split()
     return a[ld - 1]
def m_lunar(lm):
     a = u'正月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十一月 十二月'.split()
     return a[lm - 1]
def y_lunar(ly):
     y = ly
     tg = u'甲 乙 丙 丁 戊 己 庚 辛 壬 癸'.split()
     dz = u'子 丑 寅 卯 辰 巳 午 未 申 酉 戌 亥'.split()
     sx = u'鼠 牛 虎 免 龙 蛇 马 羊 猴 鸡 狗 猪'.split()
     return tg[(y - 4) % 10] + dz[(y - 4) % 12] + u' ' + sx[(y - 4) % 12] + u'年'
def date_diff(tm):
     return (tm - datetime(1901, 1, 1)).days
def get_leap_month(lunar_year):
     flag = g_lunar_month[(lunar_year - START_YEAR) / 2]
     if (lunar_year - START_YEAR) % 2:
         return flag & 0x0f
     else:
         return flag >> 4
def lunar_month_days(lunar_year, lunar_month):
     if (lunar_year < START_YEAR):
         return 30
     high, low = 0, 29
     iBit = 16 - lunar_month;
     if (lunar_month > get_leap_month(lunar_year) and get_leap_month(lunar_year)):
         iBit -= 1
     if (g_lunar_month_day[lunar_year - START_YEAR] & (1 << iBit)):
         low += 1
        
     if (lunar_month == get_leap_month(lunar_year)):
         if (g_lunar_month_day[lunar_year - START_YEAR] & (1 << (iBit -1))):
              high = 30
         else:
              high = 29
     return (high, low)
def lunar_year_days(year):
     days = 0
     for i in range(1, 13):
         (high, low) = lunar_month_days(year, i)
         days += high
         days += low
     return days
def get_ludar_date(tm):
     span_days = date_diff(tm)
     #阳历1901年2月19日为阴历1901年正月初一
     #阳历1901年1月1日到2月19日共有49天



  • v﹑1cc_﹨
  • 白丁
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
     if (span_days <49):
         year = START_YEAR - 1
         if (span_days <19):
           month = 11;  
           day = 11 + span_days
         else:
             month = 12;
             day = span_days - 18
         return (year, month, day)
     #下面从阴历1901年正月初一算起
     span_days -= 49
     year, month, day = START_YEAR, 1, 1
     #计算年
     tmp = lunar_year_days(year)
     while span_days >= tmp:
         span_days -= tmp
         year += 1
         tmp = lunar_year_days(year)
     #计算月
     (foo, tmp) = lunar_month_days(year, month)
     while span_days >= tmp:
         span_days -= tmp
         if (month == get_leap_month(year)):
             (tmp, foo) = lunar_month_days(year, month)
             if (span_days < tmp):
                 return (0, 0, 0)
             span_days -= tmp
         month += 1
         (foo, tmp) = lunar_month_days(year, month)
     #计算日
     day += span_days
     return (year, month, day)
#功能简单,只打印当月的
this_month()



登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 5回复贴,共1页
<<返回python吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示