V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
miniyao
V2EX  ›  Python

PyCharm 总是提示 unresolved attribute reference,是依据变量名?还是路径?

  •  
  •   miniyao · 2021-01-24 19:24:36 +08:00 · 1751 次点击
    这是一个创建于 1181 天前的主题,其中的信息可能已经有所发展或是发生改变。

    虽然代码运行正常,但是 IDE ( PyCharm )总是提示 Unresolved attribute reference 'strftime' for class 'timedelta' ...

    PyCharm 是依据什么规则提示的呢?代码如下:

    local_date = item.added_time + timedelta(hours=8)
    date_str = local_date.strftime('%Y-%m-%d)
    
    1 条回复    2021-01-24 19:39:38 +08:00
    renmu123
        1
    renmu123  
       2021-01-24 19:39:38 +08:00 via Android
    因为不知道你的 item.add_time 是不是 datetime 吧,你可以写个 type hint 把 local_date 标注为 datetime
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2597 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 05:05 · PVG 13:05 · LAX 22:05 · JFK 01:05
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.