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
songdg
V2EX  ›  Python

如何连接变量

  •  
  •   songdg · 2018-09-27 21:15:08 +08:00 · 1821 次点击
    这是一个创建于 2030 天前的主题,其中的信息可能已经有所发展或是发生改变。
    table = data.root.daily.ST123 是读取 pytables 文件中的一页数据,变量 n=125,如果要读取 data.root.daily.ST125 中的数据该如何使用该变量。
    5 条回复    2018-09-29 09:05:03 +08:00
    zzth370
        1
    zzth370  
       2018-09-27 23:09:15 +08:00   ❤️ 1
    可以 getattr 试试
    sww4718168
        2
    sww4718168  
       2018-09-27 23:23:18 +08:00
    ```python
    getattr(data.root.daily, 'ST{n}'.format(n=n))
    ```
    songdg
        3
    songdg  
    OP
       2018-09-28 09:11:57 +08:00
    @sww4718168 谢谢帮助,还有个问题如果要读取 data.root.daily.ST001,但是不能赋值 n=001。
    ysc3839
        4
    ysc3839  
       2018-09-28 09:58:45 +08:00 via Android   ❤️ 1
    songdg
        5
    songdg  
    OP
       2018-09-29 09:05:03 +08:00
    @ysc3839 问题解决,谢谢帮助。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1242 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 17:56 · PVG 01:56 · LAX 10:56 · JFK 13:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.