0

is there any way for me to convert a string of a python instance:

"<__main__.test instance at 0x0325E5D0>"

to an actual instance

<__main__.test instance at 0x0325E5D0>

while having keep the same data it had when being an actual instance, I haven't been able to find something like an instance() function that would act similar to str() or int()

i've tried using the suggested function shown here: PYTHON : There is a function similar to ast.literal_eval ()? but it doesn't work

advice would be much appreciated

Sigma
  • 38
  • 6

1 Answers1

0

What you maybe want is serialization to store your object for later use.

To save it

import pickle

your_class = ...

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

To load

import pickle
with open('my_instance.pickle', 'rb') as handle:
    b = pickle.load(handle)
Anaetherus
  • 41
  • 1