Maison  >  Questions et réponses  >  le corps du texte

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中文网2741 Il y a quelques jours635

répondre à tous(2)je répondrai

  • 伊谢尔伦

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

    datetime est écrit en C, il n'y a donc pas de code source 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.
    

    Vous pouvez télécharger le package de code source et voir son code source C.

    Référence : Comment trouver l'emplacement des sources du module Python ?

    répondre
    0
  • PHP中文网

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

    Maintenez simplement la touche Ctrl enfoncée et cliquez sur la fonction que vous souhaitez afficher

    répondre
    0
  • Annulerrépondre