0

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.

regards
wajih

5
Contributors
4
Replies
11
Views
7 Years
Discussion Span
Last Post by vegaseat
Featured Replies
  • I think pickle is what you want. It's a core module, so you can just import pickle. Code example [URL="http://http://www.sthurlow.com/python/lesson10/"]here[/URL], documentation [URL="http://http://docs.python.org/library/pickle.html"]here[/URL]. Read More

  • 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 Read More

1

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

Edited by Jackson William: example

1

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

0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.