这个是什么错误呢?

这个是什么错误呢?

from datetime import datetime

from utils.trans.tools import gen_trans_id


def test_trans_tool():
    """测试trans包下的tools模块"""
    id1 = gen_trans_id()
    print(id1)
    date = datetime(2015, 10, 2, 12, 30, 45)
    id2 = gen_trans_id(date)
    print(id2)


if __name__ == '__main__':
    test_trans_tool()

C:\python-projects\venv\Scripts\python.exe C:/python-projects/utils/test_module.py

Traceback (most recent call last):

  File "C:/python-projects/utils/test_module.py", line 16, in <module>

    test_trans_tool()

  File "C:/python-projects/utils/test_module.py", line 8, in test_trans_tool

    id1 = gen_trans_id()

  File "C:\python-projects\utils\trans\tools.py", line 15, in gen_trans_id

    return datetime.strptime('%Y%m%d%H%M%S%f')

TypeError: strptime() takes exactly 2 arguments (1 given)


Process finished with exit code 1


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手乔木 2019-10-29 13:53:34

同学你好:

http://img1.sycdn.imooc.com//climg/5db7d0540970080504060060.jpg

同学strptime()方法的使用格式错误。

strptime() 函数根据指定的格式把一个时间字符串解析为时间元组。

strptime(string[, format])

string -- 时间字符串。

format -- 格式化字符串。


strftime() 函数接收以时间元组,并返回以可读字符串表示的当地时间,格式由参数format决定。

time.strftime(format)

format -- 格式字符串。

http://img1.sycdn.imooc.com//climg/5db7d3ae0981d60c07420446.jpg

如果我解决了同学的问题,请采纳!学习愉快^_^。


问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
1.Python零基础入门
  • 参与学习           人
  • 提交作业       2727    份
  • 解答问题       8160    个

想要进入Python Web、爬虫、人工智能等高薪领域,你需要掌握本阶段的Python基础知识,课程安排带你高效学习轻松入门,学完你也能听得懂Python工程师的行业梗。

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师