datetime weekday (可以返回某天是一个星期的第几天)的源码只有return 0

好奇想学习一下这个weekday的源码,但是定位后发现源码里面只有一句:

weekday.PNG

 
def weekday(self):
"""Return the day of the week as an integer, where Monday is 0 and
Sunday is 6.

:rtype: int
"""
return 0

请问一下怎样才能找到它的真正源码位置? 
父类中也没找到相应的函数。
在pycharm中采用调试功能,怎样才能进入到weekday()函数中? 我采用单步执行,一下子就跳出来了。
 
import datetime
d=datetime.datetime(2016,8,6)
t=d.weekday()
print t

 
已邀请:

李魔佛 - 公众号:可转债量化分析 【论坛注册:公众号后台留言邮箱】

赞同来自:

datetime 是用 C 编写的,所以没有 Python 的源码。
 
其真正的源码在官网:
https://hg.python.org/cpython/file/tip/Modules/_datetimemodule.c
 

/* Day of week, where Monday==0, ..., Sunday==6. 1/1/1 was a Monday. */
static int
weekday(int year, int month, int day)
{
return (ymd_to_ord(year, month, day) + 6) % 7;
}

/* year, month, day -> ordinal, considering 01-Jan-0001 as day 1. */
static int
ymd_to_ord(int year, int month, int day)
{
return days_before_year(year) + days_before_month(year, month) + day;
}

static int
days_before_year(int year)
{
int y = year - 1;
/* This is incorrect if year <= 0; we really want the floor
* here. But so long as MINYEAR is 1, the smallest year this
* can see is 1.
*/
assert (year >= 1);
return y*365 + y/4 - y/100 + y/400;
}

 
 
解答于:
http://stackoverflow.com/questions/269795/how-do-i-find-the-location-of-python-module-sources
 

要回复问题请先登录注册