Show More
@@ -6,7 +6,7 b' Requires Python 2.3 or newer.' | |||||
6 |
|
6 | |||
7 | This file contains all the classes and helper functions specific to IPython. |
|
7 | This file contains all the classes and helper functions specific to IPython. | |
8 |
|
8 | |||
9 |
$Id: iplib.py 187 |
|
9 | $Id: iplib.py 1878 2006-11-03 23:00:22Z fptest $ | |
10 | """ |
|
10 | """ | |
11 |
|
11 | |||
12 | #***************************************************************************** |
|
12 | #***************************************************************************** | |
@@ -460,21 +460,19 b' class InteractiveShell(object,Magic):' | |||||
460 |
|
460 | |||
461 | # Functions to call the underlying shell. |
|
461 | # Functions to call the underlying shell. | |
462 |
|
462 | |||
463 | # utility to expand user variables via Itpl |
|
|||
464 | self.var_expand = lambda cmd: str(ItplNS(cmd.replace('#','\#'), |
|
|||
465 | self.user_ns)) |
|
|||
466 | # The first is similar to os.system, but it doesn't return a value, |
|
463 | # The first is similar to os.system, but it doesn't return a value, | |
467 | # and it allows interpolation of variables in the user's namespace. |
|
464 | # and it allows interpolation of variables in the user's namespace. | |
468 |
self.system = lambda cmd: |
|
465 | self.system = lambda cmd: \ | |
469 | header='IPython system call: ', |
|
466 | shell(self.var_expand(cmd,depth=2), | |
470 | verbose=self.rc.system_verbose) |
|
467 | header='IPython system call: ', | |
|
468 | verbose=self.rc.system_verbose) | |||
471 | # These are for getoutput and getoutputerror: |
|
469 | # These are for getoutput and getoutputerror: | |
472 | self.getoutput = lambda cmd: \ |
|
470 | self.getoutput = lambda cmd: \ | |
473 | getoutput(self.var_expand(cmd), |
|
471 | getoutput(self.var_expand(cmd,depth=2), | |
474 | header='IPython system call: ', |
|
472 | header='IPython system call: ', | |
475 | verbose=self.rc.system_verbose) |
|
473 | verbose=self.rc.system_verbose) | |
476 | self.getoutputerror = lambda cmd: \ |
|
474 | self.getoutputerror = lambda cmd: \ | |
477 | getoutputerror(self.var_expand(cmd), |
|
475 | getoutputerror(self.var_expand(cmd,depth=2), | |
478 | header='IPython system call: ', |
|
476 | header='IPython system call: ', | |
479 | verbose=self.rc.system_verbose) |
|
477 | verbose=self.rc.system_verbose) | |
480 |
|
478 | |||
@@ -616,6 +614,22 b' class InteractiveShell(object,Magic):' | |||||
616 |
|
614 | |||
617 | # end __init__ |
|
615 | # end __init__ | |
618 |
|
616 | |||
|
617 | def var_expand(self,cmd,depth=0): | |||
|
618 | """Expand python variables in a string. | |||
|
619 | ||||
|
620 | The depth argument indicates how many frames above the caller should | |||
|
621 | be walked to look for the local namespace where to expand variables. | |||
|
622 | ||||
|
623 | The global namespace for expansion is always the user's interactive | |||
|
624 | namespace. | |||
|
625 | """ | |||
|
626 | ||||
|
627 | return str(ItplNS(cmd.replace('#','\#'), | |||
|
628 | self.user_ns, # globals | |||
|
629 | # Skip our own frame in searching for locals: | |||
|
630 | sys._getframe(depth+1).f_locals # locals | |||
|
631 | )) | |||
|
632 | ||||
619 | def pre_config_initialization(self): |
|
633 | def pre_config_initialization(self): | |
620 | """Pre-configuration init method |
|
634 | """Pre-configuration init method | |
621 |
|
635 | |||
@@ -915,7 +929,7 b' class InteractiveShell(object,Magic):' | |||||
915 | if fn is None: |
|
929 | if fn is None: | |
916 | error("Magic function `%s` not found." % magic_name) |
|
930 | error("Magic function `%s` not found." % magic_name) | |
917 | else: |
|
931 | else: | |
918 | magic_args = self.var_expand(magic_args) |
|
932 | magic_args = self.var_expand(magic_args,1) | |
919 | return fn(magic_args) |
|
933 | return fn(magic_args) | |
920 |
|
934 | |||
921 | def ipalias(self,arg_s): |
|
935 | def ipalias(self,arg_s): |
@@ -23,6 +23,10 b'' | |||||
23 |
|
23 | |||
24 | 2006-11-03 Fernando Perez <Fernando.Perez@colorado.edu> |
|
24 | 2006-11-03 Fernando Perez <Fernando.Perez@colorado.edu> | |
25 |
|
25 | |||
|
26 | * IPython/iplib.py (InteractiveShell.var_expand): fix stack | |||
|
27 | handling in variable expansion so that shells and magics recognize | |||
|
28 | function local scopes correctly. Bug reported by Brian. | |||
|
29 | ||||
26 | * scripts/ipython: remove the very first entry in sys.path which |
|
30 | * scripts/ipython: remove the very first entry in sys.path which | |
27 | Python auto-inserts for scripts, so that sys.path under IPython is |
|
31 | Python auto-inserts for scripts, so that sys.path under IPython is | |
28 | as similar as possible to that under plain Python. |
|
32 | as similar as possible to that under plain Python. |
General Comments 0
You need to be logged in to leave comments.
Login now