diff --git a/doc/ChangeLog b/doc/ChangeLog index 9ac9bc8..01016ef 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -12,6 +12,8 @@ as if it was typed on IPython command prompt, i.e. as IPython script. + * example-magic.py, magic_grepl.py: remove outdated examples + 2006-12-08 Ville Vainio * Extensions/ipy_stock_completers.py.py: fix cd completer diff --git a/doc/examples/example-magic.py b/doc/examples/example-magic.py deleted file mode 100644 index c792e6c..0000000 --- a/doc/examples/example-magic.py +++ /dev/null @@ -1,36 +0,0 @@ -"""Example of how to define a magic function for extending IPython. - -The name of the function *must* begin with magic_. IPython mangles it so -that magic_foo() becomes available as %foo. - -The argument list must be *exactly* (self,parameter_s=''). - -The single string parameter_s will have the user's input. It is the magic -function's responsability to parse this string. - -That is, if the user types ->>>%foo a b c - -The followinng internal call is generated: - self.magic_foo(parameter_s='a b c'). - -To have any functions defined here available as magic functions in your -IPython environment, import this file in your configuration file with an -execfile = this_file.py statement. See the details at the end of the sample -ipythonrc file. """ - -# first define a function with the proper form: -def magic_foo(self,parameter_s=''): - """My very own magic!. (Use docstrings, IPython reads them).""" - print 'Magic function. Passed parameter is between < >: <'+parameter_s+'>' - print 'The self object is:',self - -# Add the new magic function to the class dict: -from IPython.iplib import InteractiveShell -InteractiveShell.magic_foo = magic_foo - -# And remove the global name to keep global namespace clean. Don't worry, the -# copy bound to IPython stays, we're just removing the global name. -del magic_foo - -#********************** End of file *********************** diff --git a/doc/examples/magic_grepl.py b/doc/examples/magic_grepl.py deleted file mode 100644 index 9e50113..0000000 --- a/doc/examples/magic_grepl.py +++ /dev/null @@ -1,60 +0,0 @@ -"""This function implements a simple grep-like function in pure python. - -You can enable it by copying it to your ~/.ipython directory and putting - -execfile = magic_grepl.py - -in your ipythonrc file. - -Code contributed by Gever Tulley , minor changes applied. -""" - -import glob -import re -import os - -def magic_grepl(self, parameter_s=''): - """Search for a pattern in a list of files. - - It prints the names of the files containing the pattern. Similar to 'grep - -l' in Unix-like environments. - - Usage: @grepl pattern [files] - - - pattern: any regular expression pattern which re.compile() will accept. - - files: list of files to scan. It can contain standard unix wildcards. - """ - - # argument processing - params = parameter_s.split() - if len(params) > 1: - target = params[0] # first one is the target - file_patterns = params[1:] # all the rest are filenames or patterns - - # build the regular expression - expr = re.compile(target) - - for pattern in file_patterns: - flist = [f for f in glob.glob(pattern) if os.path.isfile(f)] - for filename in flist: - # open and read the whole file - f = open(filename,'r') - data = f.read() - f.close() - - # see if pattern occurs in the file - if expr.search(data): - print filename - else: - # no parameters given - print("Usage: @grepl pattern [files]"); - -# Add the new magic function to the class dict: -from IPython.iplib import InteractiveShell -InteractiveShell.magic_grepl = magic_grepl - -# And remove the global name to keep global namespace clean. Don't worry, the -# copy bound to IPython stays, we're just removing the global name. -del magic_grepl - -#********************** End of file ***********************