推荐学习书目
› 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
alittlecode
V2EX  ›  Python

有没有方法获取到一个 py 文件中所有方法的名称,除了使用正则匹配

  •  
  •   alittlecode · Apr 2, 2021 · 3509 views
    This topic created in 2044 days ago, the information mentioned may be changed or developed.
    8 replies  •  2021-04-02 21:21:50 +08:00
    imn1
    imn1
    Apr 2, 2021
    1
    一切皆为对象
    import re
    dir(re)
    alittlecode
    alittlecode
    OP
    Apr 2, 2021
    2
    @imn1 这样把引入的变量什么的都包含了
    est
    est
    Apr 2, 2021
    3
    ast 模块
    demobin
    demobin
    Apr 2, 2021
    4
    for item in re.__all__:
    print(item, hasattr(getattr(re, item), '__call__'))
    imn1
    imn1
    Apr 2, 2021
    5
    @alittlecode #2
    你自己多想一步不行么?有个内置函数叫 callable()

    如果你想更“正式”一点,以前有个包叫 optparse,不过已经废弃了
    现在可以用 inspect,typing 之类的自己组织
    chionetw5
    chionetw5
    Apr 2, 2021
    6
    通过 importlib
    xiaolinjia
    xiaolinjia
    Apr 2, 2021
    7
    inspect.getmembers(promotions, inspect.isfunction)
    dingwen07
    dingwen07
    Apr 2, 2021 via iPhone
    8
    inspect 模块
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   877 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 21:24 · PVG 05:24 · LAX 13:24 · JFK 16:24
    ♥ Do have faith in what you're doing.