MCPcopy Index your code
hub / github.com/ipython/ipython / store

Method store

IPython/extensions/storemagic.py:80–230  ·  view source on GitHub ↗

Lightweight persistence for python variables. Example:: In [1]: l = ['hello',10,'world'] In [2]: %store l Stored 'l' (list) In [3]: exit (IPython session is closed and started again...) ville@badger:~$ ipython In [1]:

(self, parameter_s='')

Source from the content-addressed store, hash-verified

78 @skip_doctest
79 @line_magic
80 def store(self, parameter_s=''):
81 """Lightweight persistence for python variables.
82
83 Example::
84
85 In [1]: l = ['hello',10,'world']
86 In [2]: %store l
87 Stored 'l' (list)
88 In [3]: exit
89
90 (IPython session is closed and started again...)
91
92 ville@badger:~$ ipython
93 In [1]: l
94 NameError: name 'l' is not defined
95 In [2]: %store -r
96 In [3]: l
97 Out[3]: ['hello', 10, 'world']
98
99 Usage:
100
101 * ``%store`` - Show list of all variables and their current
102 values
103 * ``%store spam bar`` - Store the *current* value of the variables spam
104 and bar to disk
105 * ``%store -d spam`` - Remove the variable and its value from storage
106 * ``%store -z`` - Remove all variables from storage
107 * ``%store -r`` - Refresh all variables, aliases and directory history
108 from store (overwrite current vals)
109 * ``%store -r spam bar`` - Refresh specified variables and aliases from store
110 (delete current val)
111 * ``%store foo >a.txt`` - Store value of foo to new file a.txt
112 * ``%store foo >>a.txt`` - Append value of foo to file a.txt
113
114 It should be noted that if you change the value of a variable, you
115 need to %store it again if you want to persist the new value.
116
117 Note also that the variables will need to be pickleable; most basic
118 python types can be safely %store'd.
119
120 Also aliases can be %store'd across sessions.
121 To remove an alias from the storage, use the %unalias magic.
122 """
123
124 opts,argsl = self.parse_options(parameter_s,'drz',mode='string')
125 args = argsl.split()
126 ip = self.shell
127 db = ip.db
128 # delete
129 if 'd' in opts:
130 try:
131 todel = args[0]
132 except IndexError as e:
133 raise UsageError('You must provide the variable to forget') from e
134 else:
135 try:
136 del db['autorestore/' + todel]
137 except BaseException as e:

Callers

nothing calls this directly

Calls 11

UsageErrorClass · 0.90
restore_aliasesFunction · 0.85
restore_dataFunction · 0.85
pprintFunction · 0.85
parse_optionsMethod · 0.80
keysMethod · 0.80
sortMethod · 0.80
evMethod · 0.80
retrieve_aliasMethod · 0.80
getMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected