2016-02-19 140 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