2017-08-05 61 views
0

有什么办法,我一个Python实例的字符串转换:python将实例的字符串转换为实例?

"<__main__.test instance at 0x0325E5D0>" 

到实际情况

<__main__.test instance at 0x0325E5D0> 

,同时具有保持作为一个实际的例子,当它有同样的数据,我一直没能找到类似的实例()功能,将起到类似STR()INT()

我已经使用这里显示的提示功能的尝试: PYTHON : There is a function similar to ast.literal_eval()? ,但它不工作

建议,将不胜感激

+5

号这是不可能的。 – user2357112

+0

你知道什么'__ main __。test instance at 0x0325E5D0''是什么意思? –

+1

你试图通过这样做来达到什么目的? – karthikr

回答

0

你也许需要的是序列化存储你的对象供以后使用。

要保存它

import pickle 

your_class = ... 

with open('my_instance.pickle', 'wb') as handle: 
    pickle.dump(a, handle, protocol=pickle.HIGHEST_PROTOCOL) 

要加载

import pickle 
with open('my_instance.pickle', 'rb') as handle: 
    b = pickle.load(handle) 
相关问题