Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?


share|improve this question
up vote 13 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


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.