CoffeeRain
CoffeeRain

Reputation: 4522

Save variables in Python session?

Is there a way to save the current Python session? I would like to be able to save all my Python variables, functions, and imported libraries. If possible, having the history saved would be nice. I have looked all over Google and Stackoverflow for a simple command to do this, but have found nothing quite fitting what I want. Some suggested downloading new software, which I don't want. Others had big scripts that they wrote to do this for them.

I'm looking for a no-nonsense easy to use command. Is there one? If not, how would you suggest to make one?

UPDATE: readline.write_history_file() and readline.read_history_file() save the history.

Upvotes: 1

Views: 2014

Answers (2)

Teja
Teja

Reputation: 13534

1.) After typing all commands just do CTRL+S. 2) Give a file name and say OK.

This works for Python Shell.

Upvotes: 0

Ethan Furman
Ethan Furman

Reputation: 69031

I think the closest thing you're going to find is ipython. I'm not sure if it does the variable saving thing, but I believe it does everything else you're asking for.

Upvotes: 3

Related Questions