如何将字符串作为变量名
2个回答
2017-06-12
展开全部
可以用到java反射机制,Class和Method这些类
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
>>> var = "This is a string"
>>> varName = 'var'
>>> s= locals()[varName]
>>> s
'This is a string'
>>> s2=vars()[varName]
>>> s2
'This is a string'
>>> s3=eval(varName)
>>> s3
'This is a string'
>>> varName = 'var'
>>> s= locals()[varName]
>>> s
'This is a string'
>>> s2=vars()[varName]
>>> s2
'This is a string'
>>> s3=eval(varName)
>>> s3
'This is a string'
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询