python-根据字符串动态生成对象eval
2015-06-02 16:00
519 查看
# -*- coding: utf-8 -*- stock1={ 'stockName':"沈阳机床", 'stockCode':"000410", 'averagePrice_yesterday':34.08, 'averagePrice_today':35.49, 'position_old':0.0941350558312, } stock2={ 'stockName':"暴风科技", 'stockCode':"300431", 'averagePrice_yesterday':238.11, 'averagePrice_today':245.96, 'position_old': 0.0976148704234, } #字符串动态生成对象 eval()方法 for i in range(1,3): print eval('stock' + str(i))['stockName']+"最新仓位: ",eval('stock' + str(i))['position_old'] -------------------输出结果如下:---------------------------沈阳机床最新仓位: 0.0941350558312 暴风科技最新仓位: 0.0976148704234
相关文章推荐
- Python的dict.fromkeys应用
- Python中pip安装非PyPI官网第三方库的方法
- python 基础学习 正则表达式1(规则)
- python __name__的含义
- Python中字典创建、遍历、添加等实用操作技巧合集
- python greenlet
- 简明python教程:第2章 安装Python
- 关于python的threading.Thread.daemon 与 multiprocessing.Process.daemon的疑问
- Python:itertools模块
- python itertools的使用
- 详细记录python的range()函数用法
- Python 第十四周 字符串与正则表达式
- python编辑器对比和推荐
- 【python学习笔记一】
- Eclipse和PyDev搭建完美Python开发环境(Windows篇)
- python启动线程的3中方案
- ROS笔记:Python
- Python Version 2.7 required which was not found in the registry 问题解决
- 删除Python UserWarning[已解决]
- Python编码