Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

After running a lot of scripts in QGIS' python console, I have more than 10 dictionaries and lists, and I need these for further analysis. Is there a way to save python session, with all these variables?

In general, my question is how can I export my variables from python console to something, so that they can be loaded in again at a future time?

Thanks

share|improve this question

1 Answer 1

up vote 12 down vote accepted

If you want to access your results in other Python scripts, try the pickle module.

simple example:

>>> a = [1, 2, 3, 4, 5]
>>> import pickle
>>> f1 = open('results.pickle', 'wb')
>>> pickle.dump(a, f1)
>>> f1.close()

Now the data is saved ('pickled') in the results.pickle file.

To load the pickled data:

>>> f2 = open('results.pickle', 'rb')
>>> b = pickle.load(f2)
>>> b
[1, 2, 3, 4, 5]

pickle serializes objects for use within Python. If you want to use your data with other langauges/programs, try the json module, which has a very similar interface.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.