2016-02-19 192 views
0

一个FileStorage对象我有这个字符串:我怎样才能从字符串

str = "FieldStorage('myfile', 'file.exe', 'hello\\n')" 

所以我想知道是否有办法从字符串

+0

你为什么那样做?字符串从哪里来? –

+0

我从一个'unicode(request.post_vars [“myfile”])获得字符串'原因是因为FileStorage不能在JSON中序列化,我需要通过json传递文件@DanielRoseman –

+0

为什么不序列化需要重建对象的参数?为什么你需要序列化整个对象? –

回答

0

你可以得到FileStogare对象。问题是,如果你?

str = "FieldStorage('myfile', 'file.exe', 'hello\\n')" 
obj = eval(str) 
+0

解决了我的问题在这种情况下,这是一个_terrible_想法,因为该字符串来自用户。 –

+0

@VincentSavard我绝对同意。 – leongold