NameError: name 'datetime' is not defined

后端 未结 2 1115
终归单人心
终归单人心 2020-11-29 05:30

I\'m teaching myself Python and was just \"exploring\". Google says that datetime is a global variable but when I try to find todays date in the terminal I receive the NameE

2条回答
  •  盖世英雄少女心
    2020-11-29 06:24

    You need to import the module datetime first:

    >>> import datetime
    

    After that it works:

    >>> import datetime
    >>> date = datetime.date.today()
    >>> date
    datetime.date(2013, 11, 12)
    

提交回复
热议问题