Show More
@@ -24,6 +24,7 b' except ImportError:' | |||
|
24 | 24 | import threading |
|
25 | 25 | |
|
26 | 26 | # Our own packages |
|
27 | from IPython.core.error import StdinNotImplementedError | |
|
27 | 28 | from IPython.config.configurable import Configurable |
|
28 | 29 | from IPython.external.decorator import decorator |
|
29 | 30 | from IPython.testing.skipdoctest import skip_doctest |
@@ -761,8 +762,10 b" def magic_history(self, parameter_s = ''):" | |||
|
761 | 762 | the default is the last 10 lines. |
|
762 | 763 | |
|
763 | 764 | -f FILENAME: instead of printing the output to the screen, redirect it to |
|
764 |
the given file. The file is always overwritten, though |
|
|
765 | confirmation first if it already exists. | |
|
765 | the given file. The file is always overwritten, though *when it can*, | |
|
766 | IPython asks for confirmation first. In particular, running the command | |
|
767 | "history -f FILENAME" from the IPython Notebook interface will replace | |
|
768 | FILENAME even if it already exists *without* confirmation. | |
|
766 | 769 | |
|
767 | 770 | Examples |
|
768 | 771 | -------- |
@@ -797,10 +800,14 b" def magic_history(self, parameter_s = ''):" | |||
|
797 | 800 | close_at_end = False |
|
798 | 801 | else: |
|
799 | 802 | if os.path.exists(outfname): |
|
800 | if not io.ask_yes_no("File %r exists. Overwrite?" % outfname): | |
|
803 | try: | |
|
804 | ans = io.ask_yes_no("File %r exists. Overwrite?" % outfname) | |
|
805 | except StdinNotImplementedError: | |
|
806 | ans = True | |
|
807 | if not ans: | |
|
801 | 808 | print('Aborting.') |
|
802 | 809 | return |
|
803 | ||
|
810 | print("Overwriting file.") | |
|
804 | 811 | outfile = open(outfname,'w') |
|
805 | 812 | close_at_end = True |
|
806 | 813 |
@@ -45,6 +45,7 b' import IPython' | |||
|
45 | 45 | from IPython.core import debugger, oinspect |
|
46 | 46 | from IPython.core.error import TryNext |
|
47 | 47 | from IPython.core.error import UsageError |
|
48 | from IPython.core.error import StdinNotImplementedError | |
|
48 | 49 | from IPython.core.fakemodule import FakeModule |
|
49 | 50 | from IPython.core.profiledir import ProfileDir |
|
50 | 51 | from IPython.core.macro import Macro |
@@ -983,13 +984,22 b' Currently the magic system has the following functions:\\n"""' | |||
|
983 | 984 | |
|
984 | 985 | In [1]: 'a' in _ip.user_ns |
|
985 | 986 | Out[1]: False |
|
987 | ||
|
988 | Notes | |
|
989 | ----- | |
|
990 | Calling this magic from clients that do not implement standard input, | |
|
991 | such as the ipython notebook interface, will reset the namespace | |
|
992 | without confirmation. | |
|
986 | 993 | """ |
|
987 | 994 | opts, args = self.parse_options(parameter_s,'sf') |
|
988 | 995 | if 'f' in opts: |
|
989 | 996 | ans = True |
|
990 | 997 | else: |
|
991 | ans = self.shell.ask_yes_no( | |
|
998 | try: | |
|
999 | ans = self.shell.ask_yes_no( | |
|
992 | 1000 | "Once deleted, variables cannot be recovered. Proceed (y/[n])? ", default='n') |
|
1001 | except StdinNotImplementedError: | |
|
1002 | ans = True | |
|
993 | 1003 | if not ans: |
|
994 | 1004 | print 'Nothing done.' |
|
995 | 1005 | return |
@@ -1052,6 +1062,12 b' Currently the magic system has the following functions:\\n"""' | |||
|
1052 | 1062 | |
|
1053 | 1063 | In [11]: who_ls |
|
1054 | 1064 | Out[11]: ['a'] |
|
1065 | ||
|
1066 | Notes | |
|
1067 | ----- | |
|
1068 | Calling this magic from clients that do not implement standard input, | |
|
1069 | such as the ipython notebook interface, will reset the namespace | |
|
1070 | without confirmation. | |
|
1055 | 1071 | """ |
|
1056 | 1072 | |
|
1057 | 1073 | opts, regex = self.parse_options(parameter_s,'f') |
@@ -1059,9 +1075,12 b' Currently the magic system has the following functions:\\n"""' | |||
|
1059 | 1075 | if opts.has_key('f'): |
|
1060 | 1076 | ans = True |
|
1061 | 1077 | else: |
|
1062 | ans = self.shell.ask_yes_no( | |
|
1078 | try: | |
|
1079 | ans = self.shell.ask_yes_no( | |
|
1063 | 1080 | "Once deleted, variables cannot be recovered. Proceed (y/[n])? ", |
|
1064 | 1081 | default='n') |
|
1082 | except StdinNotImplementedError: | |
|
1083 | ans = True | |
|
1065 | 1084 | if not ans: |
|
1066 | 1085 | print 'Nothing done.' |
|
1067 | 1086 | return |
General Comments 0
You need to be logged in to leave comments.
Login now