码迷,mamicode.com
首页 > 编程语言 > 详细

python 如何把在字符串里面的名字变成变量,进行复制

时间:2017-06-02 19:38:15      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:setattr   var   variable   stat   variables   python   ber   使用   attr   

参考这几篇帖子:

https://stackoverflow.com/questions/11553721/using-a-string-variable-as-a-variable-name?answertab=active#tab-top

https://stackoverflow.com/questions/1373164/how-do-i-create-a-variable-number-of-variables

https://stackoverflow.com/questions/19122345/to-convert-string-to-variable-name

https://late.am/post/2012/04/30/the-exec-statement-and-a-python-mystery.html

和自己尝试,得出了以下几个方法时可用的。我主要是用了exec的方法,因为只是一个小脚本,而不是在类里面设置,我想在类里面,可以使用setattr的方法进行。

由于python 2 和 3的exec是不同的,所以实现的方法也略有差别。

python 如何把在字符串里面的名字变成变量,进行复制

标签:setattr   var   variable   stat   variables   python   ber   使用   attr   

原文地址:http://www.cnblogs.com/hwy89289709/p/6934822.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!