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

函数依赖的功能可扩展,怎么写最好?

  •  
  •   smdbh · May 7, 2018 · 2738 views
    This topic created in 2996 days ago, the information mentioned may be changed or developed.
    想实现的目标是,主函数 f_a(), 是个解析帧的函数,当前把不同帧格式的解析函数都写死在了主函数里。当然也可以做成 list 当参数传入。但使用这个函数就很奇怪,每次都要传这个 list,感觉这个接口不好。
    想问下有什么好的代码结构,可以解决这个问题。最好是能库函数和用户函数分离的结构。
    fushall
        1
    fushall  
       May 7, 2018
    方式很多:
    ```
    class X:
    def __init__(参数):
    pass

    def f_a(x):
    if isinstance(x, X):
    pass
    else:
    raise XXXXError('参数类型不对')
    f_a(X(xx,yy,zzz))

    def f_a(*args):
    pass

    f_a(*a_list)


    def f_a(**kwargs):
    pass

    f_a(x=xx,y=yy)

    ```
    enenaaa
        2
    enenaaa  
       May 7, 2018
    说实话没看懂你的需求是啥
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1060 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 18:21 · PVG 02:21 · LAX 11:21 · JFK 14:21
    ♥ Do have faith in what you're doing.