Hello all,
i want to save the variables present in python workspace to text file.I have used file.write() option but it converts the variables(and also arrays) to string.I want to store them as they are present in IDLE.

Is it possible?

Thanking all in anticipation.


Recommended Answers

All 4 Replies

I think pickle is what you want. It's a core module, so you can just import pickle. Code example here, documentation here.

@ Jackson William:
You had formatted the links incorrectly (forgotten http://). Fix:

Code example here, documentation here.

Also what Data type of those variables?
If they are numeric, then Just save them as strings. Then retrieve them and use int() or float() to convert them back o numerical values

Jackson William is correct, module pickle is used to save the object value and type.

Another way to do it is to save the code as a module, then use the module namespace to retrieve the variable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.