Several ways to convert python strings into variables

Source: Internet
Author: User

Turn from: http://blog.chinaunix.net/uid-20393955-id-345573.html

2011-4-18 Magnetic Needle Stone

#承接软件自动化实施与培训等gtalk: ouyangchongwu#gmail.com QQ 37391319 Blog: oychw.cublog.cn
#版权所有, reprint and publish please contact us
#python QQ Group: Shenzhen Automation Test python Group: 113938272
#武冈深圳qq群: 66250781

Here are 3 ways in which the strings in Python are converted to variables, and if there is a way, please point out, thank you.

var = "This is a string"
VarName = ' var '
s= locals () [VarName]
S2=vars () [VarName]

Print S
Print S2
Print eval (varName)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.