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

求姿势_类的批量实例化

  •  
  •   itlynn · Jun 14, 2016 · 2690 views
    This topic created in 3645 days ago, the information mentioned may be changed or developed.

    Python 中可以用 getattr()来实现工厂函数 那么问题来了,能否批量实现生成类的实例?

    4 replies    2016-06-15 17:34:49 +08:00
    aisk
        1
    aisk  
       Jun 14, 2016
    循环里生成。。。
    knightdf
        2
    knightdf  
       Jun 15, 2016
    批量生成类都可以
    sleshep
        3
    sleshep  
       Jun 15, 2016
    exec 'a%d=Class()'%i
    itlynn
        4
    itlynn  
    OP
       Jun 15, 2016 via iPhone
    @sleshep 这个我知道,有没有更 pythonic 的方式
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3748 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 55ms · UTC 04:33 · PVG 12:33 · LAX 21:33 · JFK 00:33
    ♥ Do have faith in what you're doing.