2013-05-08 21 views
0

参见此代码:如何将python源字符串解释为真正的字符串?

my_src_str = '"""hello"""' 

my_real_str = get_real_string_from_python_src_string(my_src_str) 

在这种情况下,my_src_str是在Python源代码格式的字符串表示。我想把它解释为一个真正的Python字符串。在这里我想获得hellomy_real_str。我怎样才能做到这一点?

回答

3
>>> import ast 
>>> my_src_str = '"""hello"""' 
>>> ast.literal_eval(my_src_str) 
'hello' 
+0

很酷。感谢你及时的答复! – limi 2013-05-08 09:10:27

相关问题