推荐学习书目
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 · Jan 24, 2021 · 2236 views
    This topic created in 1942 days ago, the information mentioned may be changed or developed.

    虽然代码运行正常,但是 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 replies    2021-01-24 19:39:38 +08:00
    renmu123
        1
    renmu123  
       Jan 24, 2021 via Android
    因为不知道你的 item.add_time 是不是 datetime 吧,你可以写个 type hint 把 local_date 标注为 datetime
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3493 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 04:47 · PVG 12:47 · LAX 21:47 · JFK 00:47
    ♥ Do have faith in what you're doing.