Show More
@@ -245,13 +245,16 b' class IPApi:' | |||||
245 | else: |
|
245 | else: | |
246 | self.IP.runlines('\n'.join(lines)) |
|
246 | self.IP.runlines('\n'.join(lines)) | |
247 |
|
247 | |||
248 | def to_user_ns(self,vars): |
|
248 | def to_user_ns(self,vars, interactive = True): | |
249 | """Inject a group of variables into the IPython user namespace. |
|
249 | """Inject a group of variables into the IPython user namespace. | |
250 |
|
250 | |||
251 | Inputs: |
|
251 | Inputs: | |
252 |
|
252 | |||
253 | - vars: string with variable names separated by whitespace |
|
253 | - vars: string with variable names separated by whitespace | |
254 |
|
254 | |||
|
255 | - interactive: if True (default), the var will be listed with | |||
|
256 | %whos et. al. | |||
|
257 | ||||
255 | This utility routine is meant to ease interactive debugging work, |
|
258 | This utility routine is meant to ease interactive debugging work, | |
256 | where you want to easily propagate some internal variable in your code |
|
259 | where you want to easily propagate some internal variable in your code | |
257 | up to the interactive namespace for further exploration. |
|
260 | up to the interactive namespace for further exploration. | |
@@ -296,10 +299,15 b' class IPApi:' | |||||
296 | cf = sys._getframe(1) |
|
299 | cf = sys._getframe(1) | |
297 |
|
300 | |||
298 | user_ns = self.user_ns |
|
301 | user_ns = self.user_ns | |
299 |
|
302 | config_ns = self.IP.user_config_ns | ||
300 | for name in vars.split(): |
|
303 | for name in vars.split(): | |
301 | try: |
|
304 | try: | |
302 |
|
|
305 | val = eval(name,cf.f_globals,cf.f_locals) | |
|
306 | user_ns[name] = val | |||
|
307 | if not interactive: | |||
|
308 | config_ns[name] = val | |||
|
309 | else: | |||
|
310 | config_ns.pop(name,None) | |||
303 | except: |
|
311 | except: | |
304 | print ('could not get var. %s from %s' % |
|
312 | print ('could not get var. %s from %s' % | |
305 | (name,cf.f_code.co_name)) |
|
313 | (name,cf.f_code.co_name)) |
@@ -1,3 +1,9 b'' | |||||
|
1 | 2007-06-13 Ville Vainio <vivainio@gmail.com> | |||
|
2 | ||||
|
3 | * ipapi.py: _ip.to_user_ns(vars, interactive = True). | |||
|
4 | Added kw arg 'interactive', tell whether vars should be visible | |||
|
5 | with %whos. | |||
|
6 | ||||
1 | 2007-06-11 Ville Vainio <vivainio@gmail.com> |
|
7 | 2007-06-11 Ville Vainio <vivainio@gmail.com> | |
2 |
|
8 | |||
3 | * pspersistence.py, Magic.py, iplib.py: directory history now saved |
|
9 | * pspersistence.py, Magic.py, iplib.py: directory history now saved |
General Comments 0
You need to be logged in to leave comments.
Login now