For know where python stores his default modules which we could include via "import module_name":
$ python -c 'import sys; print "\n".join(sys.path)'
for me it was /usr/lib/python2.7
so create file savemodule.py in this dir with this content:
import readline
"""Use savemodule.save(file_path) for saving your console-written module"""
def get_all_hist():
l = readline.get_current_history_length()
paper = ""
for i in range(l):
paper+=readline.get_history_item(i).__str__()+"\n"
return paper
def save(*path):
if len(path)==0:
print "usage: save(file_path)"
else:
histfile=open(path[0],'w')
histfile.write(get_all_hist())
histfile.close()
viola!:) now we can write code in python console as much as we want, thenimport savemodule
savemodule.__doc__
savemodule.save(/path/to/file/where/we/want/save)