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

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

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

    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

直接按住ctrl,再点击你要查看的函数就可以了


datetime 是用 C 编写的,所以没有 Python 的源码。

In [28]: import datetime

In [29]: datetime.__file__
Out[29]: '/usr/lib/python2.7/lib-dynload/datetime.so'

In [30]: datetime?
Type:        module
String form: <module 'datetime' from '/usr/lib/python2.7/lib-dynload/datetime.so'>
File:        /usr/lib/python2.7/lib-dynload/datetime.so
Docstring:   Fast implementation of the datetime type.

可以下载源码包,看它的 C 源码。

参考: How do I find the location of Python module sources?

【热门文章】
【热门文章】