search

Home  >  Q&A  >  body text

python - 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
PHP中文网PHP中文网2812 days ago680

reply all(2)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-18 09:22:34

    datetime is written in C, so there is no Python source code.

    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.
    

    You can download the source code package and see its C source code.

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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:22:34

    Just hold down ctrl and click on the function you want to view

    reply
    0
  • Cancelreply